mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 02:30:41 -08:00
Code review changes
This commit is contained in:
parent
8c2c46b20f
commit
d38755b42a
4 changed files with 20 additions and 8 deletions
|
|
@ -248,7 +248,7 @@ Run the Web UI on your smartphone for easy access on the go. Check out the dedic
|
|||
- **File API from G4F:** [/docs/file](docs/file.md)
|
||||
- **PydanticAI and LangChain Integration for G4F:** [/docs/pydantic_ai](docs/pydantic_ai.md)
|
||||
- **Legacy API with python modules:** [/docs/legacy](docs/legacy.md)
|
||||
- **G4F - Media Documentation** [/docs/media](/docs/meda.md) *(New)*
|
||||
- **G4F - Media Documentation** [/docs/media](/docs/media.md) *(New)*
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -2134,11 +2134,20 @@ window.addEventListener('load', async function() {
|
|||
return await load_conversation(JSON.parse(appStorage.getItem(`conversation:${window.conversation_id}`)));
|
||||
}
|
||||
let conversation = await response.json();
|
||||
if (!window.conversation_id || conversation.id == window.conversation_id) {
|
||||
window.conversation_id = conversation.id;
|
||||
if (!appStorage.getItem(`conversation:${window.conversation_id}`) || conversation.id == window.conversation_id) {
|
||||
// Copy conversation from share
|
||||
if (conversation.id != window.conversation_id) {
|
||||
conversation.id = window.conversation_id;
|
||||
conversation.updated = Date.now();
|
||||
window.share_id = null;
|
||||
}
|
||||
await load_conversation(conversation);
|
||||
await save_conversation(window.conversation_id, JSON.stringify(conversation));
|
||||
await save_conversation(conversation.id, JSON.stringify(conversation));
|
||||
await load_conversations();
|
||||
if (!window.share_id) {
|
||||
// Continue after copy conversation
|
||||
return;
|
||||
}
|
||||
let refreshOnHide = true;
|
||||
document.addEventListener("visibilitychange", () => {
|
||||
if (document.hidden) {
|
||||
|
|
@ -2147,6 +2156,7 @@ window.addEventListener('load', async function() {
|
|||
refreshOnHide = true;
|
||||
}
|
||||
});
|
||||
// Start chat mode (QRCode)
|
||||
var refreshIntervalId = setInterval(async () => {
|
||||
if (!window.share_id) {
|
||||
clearInterval(refreshIntervalId);
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ class Website:
|
|||
|
||||
def _share_id(self, share_id, conversation_id: str = ""):
|
||||
share_url = os.environ.get("G4F_SHARE_URL", "")
|
||||
conversation_id = conversation_id if conversation_id else str(uuid.uuid4())
|
||||
return render_template('index.html', share_url=share_url, share_id=share_id, conversation_id=conversation_id)
|
||||
|
||||
def _index(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue