Code review changes

This commit is contained in:
hlohaus 2025-03-30 17:57:42 +02:00
parent 8c2c46b20f
commit d38755b42a
4 changed files with 20 additions and 8 deletions

View file

@ -117,6 +117,7 @@ asyncio.run(main())
### **Multiple Providers with API Keys**
```python
import os
import g4f.Provider
from g4f.client import Client
# Using environment variables
@ -126,10 +127,10 @@ providers = {
}
for provider_name, api_key in providers.items():
client = Client(provider=provider_name, api_key=api_key)
client = Client(provider=getattr(g4f.Provider, provider_name), api_key=api_key)
response = client.chat.completions.create(
model="claude-3.5-sonnet",
messages=[{"role": "user", "content": f"Hello from {provider_name}!"}]
messages=[{"role": "user", "content": f"Hello to {provider_name}!"}]
)
print(f"{provider_name}: {response.choices[0].message.content}")
```
@ -156,7 +157,7 @@ response = client.chat.completions.create(
messages="Hello Google",
cookies={
"__Secure-1PSID": "your_cookie_value_here",
"__Secure-1PSIDTS": "timestamp_value_here"
"__Secure-1PSIDTS": "your_cookie_value_here"
}
)
print(f"Gemini: {response.choices[0].message.content}")