返回提交历史
Modified
README.md
+1
-1
Modified
docs/authentication.md
+4
-3
Modified
g4f/gui/client/static/js/chat.v1.js
+14
-4
Modified
g4f/gui/server/website.py
+1
-0
XFEstudio/gpt4free
Code review changes
d38755b4
代码差异
4 个文件
+20
-8
@@ -248,7 +248,7 @@ Run the Web UI on your smartphone for easy access on the go. Check out the dedic
248
248
- **File API from G4F:** [/docs/file](docs/file.md)
249
249
- **PydanticAI and LangChain Integration for G4F:** [/docs/pydantic_ai](docs/pydantic_ai.md)
250
250
- **Legacy API with python modules:** [/docs/legacy](docs/legacy.md)
251
- **G4F - Media Documentation** [/docs/media](/docs/meda.md) *(New)*
251
- **G4F - Media Documentation** [/docs/media](/docs/media.md) *(New)*
252
252
253
253
---
254
254
@@ -117,6 +117,7 @@ asyncio.run(main())
117
117
### **Multiple Providers with API Keys**
118
118
```python
119
119
import os
120
import g4f.Provider
120
121
from g4f.client import Client
121
122
122
123
# Using environment variables
@@ -126,10 +127,10 @@ providers = {
126
127
}
127
128
128
129
for provider_name, api_key in providers.items():
129
client = Client(provider=provider_name, api_key=api_key)
130
client = Client(provider=getattr(g4f.Provider, provider_name), api_key=api_key)
130
131
response = client.chat.completions.create(
131
132
model="claude-3.5-sonnet",
132
messages=[{"role": "user", "content": f"Hello from {provider_name}!"}]
133
messages=[{"role": "user", "content": f"Hello to {provider_name}!"}]
133
134
)
134
135
print(f"{provider_name}: {response.choices[0].message.content}")
135
136
```
@@ -156,7 +157,7 @@ response = client.chat.completions.create(
156
157
messages="Hello Google",
157
158
cookies={
158
159
"__Secure-1PSID": "your_cookie_value_here",
159
"__Secure-1PSIDTS": "timestamp_value_here"
160
"__Secure-1PSIDTS": "your_cookie_value_here"
160
161
}
161
162
)
162
163
print(f"Gemini: {response.choices[0].message.content}")
@@ -2134,11 +2134,20 @@ window.addEventListener('load', async function() {
2134
2134
return await load_conversation(JSON.parse(appStorage.getItem(`conversation:${window.conversation_id}`)));
2135
2135
}
2136
2136
let conversation = await response.json();
2137
if (!window.conversation_id || conversation.id == window.conversation_id) {
2138
window.conversation_id = conversation.id;
2139
await load_conversation(conversation);
2140
await save_conversation(window.conversation_id, JSON.stringify(conversation));
2137
if (!appStorage.getItem(`conversation:${window.conversation_id}`) || conversation.id == window.conversation_id) {
2138
// Copy conversation from share
2139
if (conversation.id != window.conversation_id) {
2140
conversation.id = window.conversation_id;
2141
conversation.updated = Date.now();
2142
window.share_id = null;
2143
}
2144
await load_conversation(conversation);
2145
await save_conversation(conversation.id, JSON.stringify(conversation));
2141
2146
await load_conversations();
2147
if (!window.share_id) {
2148
// Continue after copy conversation
2149
return;
2150
}
2142
2151
let refreshOnHide = true;
2143
2152
document.addEventListener("visibilitychange", () => {
2144
2153
if (document.hidden) {
@@ -2147,6 +2156,7 @@ window.addEventListener('load', async function() {
2147
2156
refreshOnHide = true;
2148
2157
}
2149
2158
});
2159
// Start chat mode (QRCode)
2150
2160
var refreshIntervalId = setInterval(async () => {
2151
2161
if (!window.share_id) {
2152
2162
clearInterval(refreshIntervalId);
@@ -52,6 +52,7 @@ class Website:
52
52
53
53
def _share_id(self, share_id, conversation_id: str = ""):
54
54
share_url = os.environ.get("G4F_SHARE_URL", "")
55
conversation_id = conversation_id if conversation_id else str(uuid.uuid4())
55
56
return render_template('index.html', share_url=share_url, share_id=share_id, conversation_id=conversation_id)
56
57
57
58
def _index(self):