Skip to content

Commit

Permalink
Use other model for copilot
Browse files Browse the repository at this point in the history
  • Loading branch information
hlohaus committed Dec 16, 2024
1 parent 5b76f2c commit 75cb616
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion etc/tool/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
GITHUB_REPOSITORY = os.getenv('GITHUB_REPOSITORY')
G4F_PROVIDER = os.getenv('G4F_PROVIDER')
G4F_MODEL = os.getenv('G4F_MODEL') or g4f.models.default
G4F_MODEL = os.getenv('G4F_MODEL') or g4f.models.gpt_4

def get_pr_details(github: Github) -> PullRequest:
"""
Expand Down
22 changes: 11 additions & 11 deletions g4f/Provider/PollinationsAI.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@
class PollinationsAI(OpenaiAPI):
label = "Pollinations AI"
url = "https://pollinations.ai"

working = True
needs_auth = False
supports_stream = True

api_base = "https://text.pollinations.ai/openai"

default_model = "openai"

additional_models_image = ["midjourney", "dall-e-3"]
additional_models_text = ["sur", "sur-mistral", "claude"]

model_aliases = {
"gpt-4o": "openai",
"mistral-nemo": "mistral",
Expand Down Expand Up @@ -66,7 +64,6 @@ async def create_async_generator(
model: str,
messages: Messages,
prompt: str = None,
api_base: str = "https://text.pollinations.ai/openai",
api_key: str = None,
proxy: str = None,
seed: str = None,
Expand All @@ -76,25 +73,28 @@ async def create_async_generator(
) -> AsyncResult:
model = cls.get_model(model)
if model in cls.image_models:
async for response in cls._generate_image(model, messages, prompt, seed, width, height):
async for response in cls._generate_image(model, messages, prompt, proxy, seed, width, height):
yield response
elif model in cls.models:
async for response in cls._generate_text(model, messages, api_base, api_key, proxy, **kwargs):
async for response in cls._generate_text(model, messages, api_key, proxy, **kwargs):
yield response
else:
raise ValueError(f"Unknown model: {model}")

@classmethod
async def _generate_image(cls, model: str, messages: Messages, prompt: str = None, seed: str = None, width: int = 1024, height: int = 1024):
async def _generate_image(cls, model: str, messages: Messages, prompt: str = None, proxy: str = None, seed: str = None, width: int = 1024, height: int = 1024):
if prompt is None:
prompt = messages[-1]["content"]
if seed is None:
seed = random.randint(0, 100000)
image = f"https://image.pollinations.ai/prompt/{quote(prompt)}?width={width}&height={height}&seed={int(seed)}&nofeed=true&nologo=true&model={quote(model)}"
async with ClientSession(connector=get_connector(proxy=proxy), headers=cls.headers) as session:
async with session.get(image) as response:
await raise_for_status(response)
yield ImageResponse(image, prompt)

@classmethod
async def _generate_text(cls, model: str, messages: Messages, api_base: str, api_key: str = None, proxy: str = None, **kwargs):
async def _generate_text(cls, model: str, messages: Messages, api_key: str = None, proxy: str = None, **kwargs):
if api_key is None:
async with ClientSession(connector=get_connector(proxy=proxy), headers=cls.headers) as session:
prompt = format_prompt(messages)
Expand All @@ -104,6 +104,6 @@ async def _generate_text(cls, model: str, messages: Messages, api_base: str, api
yield line.decode(errors="ignore")
else:
async for chunk in super().create_async_generator(
model, messages, api_base=api_base, proxy=proxy, **kwargs
model, messages, proxy=proxy, **kwargs
):
yield chunk
yield chunk
4 changes: 1 addition & 3 deletions g4f/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
HuggingFace,
Liaobots,
Airforce,
Mhystical,
MetaAI,
MicrosoftDesigner,
OpenaiChat,
Expand Down Expand Up @@ -68,7 +67,6 @@ class ImageModel(Model):
best_provider = IterListProvider([
DDG,
Pizzagpt,
ReplicateHome,
Blackbox2,
Blackbox,
Copilot,
Expand All @@ -78,7 +76,7 @@ class ImageModel(Model):
Cloudflare,
PollinationsAI,
ChatGptEs,
ChatGpt,
OpenaiChat,
])
)

Expand Down

0 comments on commit 75cb616

Please sign in to comment.