Skip to content

Commit

Permalink
~
Browse files Browse the repository at this point in the history
automatic models fetching in GUI.
  • Loading branch information
xtekky committed Oct 19, 2023
1 parent 76083c5 commit d4ab83a
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 151 deletions.
132 changes: 72 additions & 60 deletions g4f/Provider/Vercel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import json, base64, requests, execjs, random, uuid

from ..typing import Messages, TypedDict, CreateResult
from ..typing import Messages, TypedDict, CreateResult, Any
from .base_provider import BaseProvider
from abc import abstractmethod
from ..debug import logging


class Vercel(BaseProvider):
Expand All @@ -19,14 +20,16 @@ def create_completion(
model: str,
messages: Messages,
stream: bool,
proxy: str = None,
**kwargs
) -> CreateResult:
proxy: str = None, **kwargs) -> CreateResult:

print(model)

if not model:
model = "gpt-3.5-turbo"

elif model not in model_info:
raise ValueError(f"Model are not supported: {model}")

raise ValueError(f"Vercel does not support {model}")
headers = {
'authority' : 'sdk.vercel.ai',
'accept' : '*/*',
Expand Down Expand Up @@ -110,40 +113,49 @@ class ModelInfo(TypedDict):
default_params: dict[str, Any]

model_info: dict[str, ModelInfo] = {
'claude-instant-v1': {
'id': 'anthropic:claude-instant-v1',
'default_params': {
'temperature': 1,
'maximumLength': 1024,
'topP': 1,
'topK': 1,
'presencePenalty': 1,
'frequencyPenalty': 1,
'stopSequences': ['\n\nHuman:'],
},
},
'claude-v1': {
'id': 'anthropic:claude-v1',
'default_params': {
'temperature': 1,
'maximumLength': 1024,
'topP': 1,
'topK': 1,
'presencePenalty': 1,
'frequencyPenalty': 1,
'stopSequences': ['\n\nHuman:'],
},
},
'claude-v2': {
'id': 'anthropic:claude-v2',
# 'claude-instant-v1': {
# 'id': 'anthropic:claude-instant-v1',
# 'default_params': {
# 'temperature': 1,
# 'maximumLength': 1024,
# 'topP': 1,
# 'topK': 1,
# 'presencePenalty': 1,
# 'frequencyPenalty': 1,
# 'stopSequences': ['\n\nHuman:'],
# },
# },
# 'claude-v1': {
# 'id': 'anthropic:claude-v1',
# 'default_params': {
# 'temperature': 1,
# 'maximumLength': 1024,
# 'topP': 1,
# 'topK': 1,
# 'presencePenalty': 1,
# 'frequencyPenalty': 1,
# 'stopSequences': ['\n\nHuman:'],
# },
# },
# 'claude-v2': {
# 'id': 'anthropic:claude-v2',
# 'default_params': {
# 'temperature': 1,
# 'maximumLength': 1024,
# 'topP': 1,
# 'topK': 1,
# 'presencePenalty': 1,
# 'frequencyPenalty': 1,
# 'stopSequences': ['\n\nHuman:'],
# },
# },
'replicate/llama70b-v2-chat': {
'id': 'replicate:replicate/llama-2-70b-chat',
'default_params': {
'temperature': 1,
'maximumLength': 1024,
'temperature': 0.75,
'maximumLength': 3000,
'topP': 1,
'topK': 1,
'presencePenalty': 1,
'frequencyPenalty': 1,
'stopSequences': ['\n\nHuman:'],
'repetitionPenalty': 1,
},
},
'a16z-infra/llama7b-v2-chat': {
Expand Down Expand Up @@ -254,28 +266,28 @@ class ModelInfo(TypedDict):
'stopSequences': [],
},
},
'gpt-4': {
'id': 'openai:gpt-4',
'default_params': {
'temperature': 0.7,
'maximumLength': 8192,
'topP': 1,
'presencePenalty': 0,
'frequencyPenalty': 0,
'stopSequences': [],
},
},
'gpt-4-0613': {
'id': 'openai:gpt-4-0613',
'default_params': {
'temperature': 0.7,
'maximumLength': 8192,
'topP': 1,
'presencePenalty': 0,
'frequencyPenalty': 0,
'stopSequences': [],
},
},
# 'gpt-4': {
# 'id': 'openai:gpt-4',
# 'default_params': {
# 'temperature': 0.7,
# 'maximumLength': 8192,
# 'topP': 1,
# 'presencePenalty': 0,
# 'frequencyPenalty': 0,
# 'stopSequences': [],
# },
# },
# 'gpt-4-0613': {
# 'id': 'openai:gpt-4-0613',
# 'default_params': {
# 'temperature': 0.7,
# 'maximumLength': 8192,
# 'topP': 1,
# 'presencePenalty': 0,
# 'frequencyPenalty': 0,
# 'stopSequences': [],
# },
# },
'code-davinci-002': {
'id': 'openai:code-davinci-002',
'default_params': {
Expand Down
41 changes: 17 additions & 24 deletions g4f/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from __future__ import annotations
from requests import get
from g4f.models import Model, ModelUtils
from .Provider import BaseProvider, RetryProvider
from .typing import Messages, CreateResult, Union, List
from .debug import logging
from requests import get
from .models import Model, ModelUtils, _all_models
from .Provider import BaseProvider, RetryProvider
from .typing import Messages, CreateResult, Union, List
from .debug import logging

version = '0.1.6.6'
version = '0.1.6.6'
version_check = True


def check_pypi_version() -> None:
try:
response = get("https://pypi.org/pypi/g4f/json").json()
Expand All @@ -20,7 +19,6 @@ def check_pypi_version() -> None:
except Exception as e:
print(f'Failed to check g4f pypi version: {e}')


def get_model_and_provider(model : Union[Model, str],
provider : Union[type[BaseProvider], None],
stream : bool,
Expand Down Expand Up @@ -56,7 +54,7 @@ def get_model_and_provider(model : Union[Model, str],

class ChatCompletion:
@staticmethod
def create(model: Union[Model, str],
def create(model : Union[Model, str],
messages : Messages,
provider : Union[type[BaseProvider], None] = None,
stream : bool = False,
Expand All @@ -76,12 +74,11 @@ def create(model: Union[Model, str],
return result if stream else ''.join(result)

@staticmethod
async def create_async(
model : Union[Model, str],
messages: Messages,
provider: Union[type[BaseProvider], None] = None,
stream : bool = False,
ignored : List[str] = None, **kwargs) -> str:
async def create_async(model : Union[Model, str],
messages : Messages,
provider : Union[type[BaseProvider], None] = None,
stream : bool = False,
ignored : List[str] = None, **kwargs) -> str:

if stream:
raise ValueError(f'"create_async" does not support "stream" argument')
Expand All @@ -90,17 +87,13 @@ async def create_async(

return await provider.create_async(model.name, messages, **kwargs)


class Completion:
@staticmethod
def create(
model: str,
prompt: str,
provider: Union[type[BaseProvider], None] = None,
stream: bool = False,
ignored : List[str] = None,
**kwargs
) -> Union[CreateResult, str]:
def create(model : Union[Model, str],
prompt : str,
provider : Union[type[BaseProvider], None] = None,
stream : bool = False,
ignored : List[str] = None, **kwargs) -> Union[CreateResult, str]:

allowed_models = [
'code-davinci-002',
Expand Down
9 changes: 1 addition & 8 deletions g4f/gui/client/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,7 @@
</div>
<div class="field">
<select name="model" id="model">
<option value="gpt-3.5-turbo" selected>gpt-3.5</option>
<option value="gpt-3.5-turbo-0613">gpt-3.5 fast</option>
<option value="gpt-3.5-turbo-16k">gpt-3.5 16k</option>
<option value="gpt-3.5-turbo-16k-0613">gpt-3.5 16k fast</option>
<option value="gpt-4">gpt-4</option>
<option value="gpt-4-0613">gpt-4 fast</option>
<option value="gpt-4-32k">gpt-4 32k</option>
<option value="gpt-4-32k-0613">gpt-4 32k fast</option>
<option value="gpt-3.5-turbo" selected>gpt-3.5-turbo</option>
</select>
</div>
<div class="field">
Expand Down
Loading

0 comments on commit d4ab83a

Please sign in to comment.