Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some arguments to chat completion api, update discord links #2435

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ docker pull hlohaus789/g4f
- **For comprehensive details on new features and updates, please refer to our** [Releases](https://github.com/xtekky/gpt4free/releases) **page**
- **Installation Guide for Windows (.exe):** 💻 [Installation Guide for Windows (.exe)](#installation-guide-for-windows-exe)
- **Join our Telegram Channel:** 📨 [telegram.me/g4f_channel](https://telegram.me/g4f_channel)
- **Join our Discord Group:** 💬🆕️ [discord.gg/6yrm7H4B](https://discord.gg/6yrm7H4B)
- **Join our Discord Group:** 💬🆕️ [discord.gg/vE7gCvss](https://discord.gg/vE7gCvss)


## 🔻 Site Takedown
Expand Down
1 change: 0 additions & 1 deletion g4f/Provider/Copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from ..Provider.openai.har_file import NoValidHarFileError, get_headers, get_har_files
from ..requests import get_nodriver
from ..image import ImageResponse, to_bytes, is_accepted_format
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
from ..cookies import get_cookies_dir
from .. import debug

class Conversation(BaseConversation):
Expand Down
3 changes: 3 additions & 0 deletions g4f/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class ChatCompletionsConfig(BaseModel):
web_search: Optional[bool] = None
proxy: Optional[str] = None
conversation_id: Optional[str] = None
history_disabled: Optional[bool] = None
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
auto_continue: Optional[bool] = None
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
timeout: Optional[int] = None
hlohaus marked this conversation as resolved.
Show resolved Hide resolved

class ImageGenerationConfig(BaseModel):
prompt: str
Expand Down
4 changes: 2 additions & 2 deletions g4f/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Union, AsyncIterator, Iterator, Coroutine, Optional

from ..image import ImageResponse, copy_images, images_dir
from ..typing import Messages, Image, ImageType
from ..typing import Messages, ImageType
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
from ..providers.types import ProviderType
from ..providers.response import ResponseType, FinishReason, BaseConversation, SynthesizeData
from ..errors import NoImageResponseError, ModelNotFoundError
Expand Down Expand Up @@ -332,7 +332,7 @@ async def async_generate(

def create_variation(
self,
image: Union[str, bytes],
image: ImageType,
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
model: str = None,
provider: Optional[ProviderType] = None,
response_format: str = "url",
Expand Down
5 changes: 3 additions & 2 deletions g4f/client/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ def get_model_and_provider(model : Union[Model, str],
model = provider.default_model if hasattr(provider, "default_model") else ""
else:
raise ModelNotFoundError(f'Model not found: {model}')
else:
elif isinstance(model, Model):
provider = model.best_provider

else:
raise ValueError(f"Unexpected type: {type(model)}")
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
if not provider:
raise ProviderNotFoundError(f'No provider found for model: {model}')

Expand Down
6 changes: 3 additions & 3 deletions g4f/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import_error = e

def get_gui_app():
if import_error is not None:
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
raise MissingRequirementsError(f'Install "gui" requirements | pip install -U g4f[gui]\n{import_error}')

site = Website(app)
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
for route in site.routes:
app.add_url_rule(
Expand All @@ -27,9 +30,6 @@ def get_gui_app():
return app

def run_gui(host: str = '0.0.0.0', port: int = 8080, debug: bool = False) -> None:
if import_error is not None:
raise MissingRequirementsError(f'Install "gui" requirements | pip install -U g4f[gui]\n{import_error}')

config = {
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
'host' : host,
'port' : port,
Expand Down
2 changes: 1 addition & 1 deletion g4f/gui/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</button>
<div class="info">
<i class="fa-brands fa-discord"></i>
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
<span class="convo-title">discord ~ <a href="https://discord.gg/6yrm7H4B" target="_blank">discord.gg/6yrm7H4B</a>
<span class="convo-title">discord ~ <a href="https://discord.gg/vE7gCvss" target="_blank">discord.gg/vE7gCvss</a>
</span>
</div>
<div class="info">
Expand Down
4 changes: 1 addition & 3 deletions g4f/gui/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,9 @@ def _prepare_conversation_kwargs(self, json_data: dict, kwargs: dict):
}

def _create_response_stream(self, kwargs: dict, conversation_id: str, provider: str, download_images: bool = True) -> Iterator:
debug.logs = []
print_callback = debug.log_handler
def log_handler(text: str):
debug.logs.append(text)
print_callback(text)
print(text)
hlohaus marked this conversation as resolved.
Show resolved Hide resolved
debug.log_handler = log_handler
try:
result = ChatCompletion.create(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion g4f/gui/server/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ def _chat(self, conversation_id):
return render_template('index.html', chat_id=conversation_id)

def _index(self):
return render_template('index.html', chat_id=str(uuid.uuid4()))
return render_template('index.html', chat_id=str(uuid.uuid4()))