diff --git a/README.md b/README.md index 442d3f2c..6d2f086f 100644 --- a/README.md +++ b/README.md @@ -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)* --- diff --git a/docs/authentication.md b/docs/authentication.md index 2d9bd65d..01336fd9 100644 --- a/docs/authentication.md +++ b/docs/authentication.md @@ -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}") diff --git a/g4f/gui/client/static/js/chat.v1.js b/g4f/gui/client/static/js/chat.v1.js index 40768172..66089f3d 100644 --- a/g4f/gui/client/static/js/chat.v1.js +++ b/g4f/gui/client/static/js/chat.v1.js @@ -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; - await load_conversation(conversation); - await save_conversation(window.conversation_id, JSON.stringify(conversation)); + 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(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); diff --git a/g4f/gui/server/website.py b/g4f/gui/server/website.py index d2c30cab..f3145cbc 100644 --- a/g4f/gui/server/website.py +++ b/g4f/gui/server/website.py @@ -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):