move proxy server unique id to header
This commit is contained in:
parent
96b65afeb5
commit
82b03aeb08
4 changed files with 23 additions and 15 deletions
|
|
@ -37,6 +37,8 @@ def get_error_title(e: Exception) -> str:
|
|||
return "The request failed. Please check your internet connection and try again. If this issue persists, you can use our API key for free by going to VS Code settings and changing the value of continue.OPENAI_API_KEY to \"\""
|
||||
elif isinstance(e, openai_errors.InvalidRequestError):
|
||||
return 'Invalid request sent to OpenAI. Please try again.'
|
||||
elif "rate_limit_ip_middleware" in e.__str__():
|
||||
return 'You have reached your limit for free usage of our token. You can continue using Continue by entering your own OpenAI API key in VS Code settings.'
|
||||
elif e.__str__().startswith("Cannot connect to host"):
|
||||
return "The request failed. Please check your internet connection and try again."
|
||||
return e.__str__() or e.__repr__()
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
from functools import cached_property
|
||||
import json
|
||||
import traceback
|
||||
from typing import Any, Callable, Coroutine, Dict, Generator, List, Literal, Union
|
||||
|
|
@ -37,6 +36,10 @@ class ProxyServer(LLM):
|
|||
|
||||
def count_tokens(self, text: str):
|
||||
return count_tokens(self.default_model, text)
|
||||
|
||||
def get_headers(self):
|
||||
# headers with unique id
|
||||
return {"unique_id": self.unique_id}
|
||||
|
||||
async def complete(self, prompt: str, with_history: List[ChatMessage] = None, **kwargs) -> Coroutine[Any, Any, str]:
|
||||
args = {**self.default_args, **kwargs}
|
||||
|
|
@ -47,16 +50,15 @@ class ProxyServer(LLM):
|
|||
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl_context=ssl_context)) as session:
|
||||
async with session.post(f"{SERVER_URL}/complete", json={
|
||||
"messages": messages,
|
||||
"unique_id": self.unique_id,
|
||||
**args
|
||||
}) as resp:
|
||||
try:
|
||||
response_text = await resp.text()
|
||||
self.write_log(f"Completion: \n\n{response_text}")
|
||||
return response_text
|
||||
except:
|
||||
}, headers=self.get_headers()) as resp:
|
||||
if resp.status != 200:
|
||||
raise Exception(await resp.text())
|
||||
|
||||
response_text = await resp.text()
|
||||
self.write_log(f"Completion: \n\n{response_text}")
|
||||
return response_text
|
||||
|
||||
async def stream_chat(self, messages: List[ChatMessage] = None, **kwargs) -> Coroutine[Any, Any, Generator[Union[Any, List, Dict], None, None]]:
|
||||
args = {**self.default_args, **kwargs}
|
||||
messages = compile_chat_messages(
|
||||
|
|
@ -66,11 +68,12 @@ class ProxyServer(LLM):
|
|||
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl_context=ssl_context)) as session:
|
||||
async with session.post(f"{SERVER_URL}/stream_chat", json={
|
||||
"messages": messages,
|
||||
"unique_id": self.unique_id,
|
||||
**args
|
||||
}) as resp:
|
||||
}, headers=self.get_headers()) as resp:
|
||||
# This is streaming application/json instaed of text/event-stream
|
||||
completion = ""
|
||||
if resp.status != 200:
|
||||
raise Exception(await resp.text())
|
||||
async for line in resp.content.iter_chunks():
|
||||
if line[1]:
|
||||
try:
|
||||
|
|
@ -86,6 +89,8 @@ class ProxyServer(LLM):
|
|||
except Exception as e:
|
||||
capture_event(self.unique_id, "proxy_server_parse_error", {
|
||||
"error_title": "Proxy server stream_chat parsing failed", "error_message": '\n'.join(traceback.format_exception(e))})
|
||||
else:
|
||||
break
|
||||
|
||||
self.write_log(f"Completion: \n\n{completion}")
|
||||
|
||||
|
|
@ -98,10 +103,11 @@ class ProxyServer(LLM):
|
|||
async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(ssl_context=ssl_context)) as session:
|
||||
async with session.post(f"{SERVER_URL}/stream_complete", json={
|
||||
"messages": messages,
|
||||
"unique_id": self.unique_id,
|
||||
**args
|
||||
}) as resp:
|
||||
}, headers=self.get_headers()) as resp:
|
||||
completion = ""
|
||||
if resp.status != 200:
|
||||
raise Exception(await resp.text())
|
||||
async for line in resp.content.iter_any():
|
||||
if line:
|
||||
try:
|
||||
|
|
|
|||
4
extension/package-lock.json
generated
4
extension/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"version": "0.0.189",
|
||||
"version": "0.0.190",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "continue",
|
||||
"version": "0.0.189",
|
||||
"version": "0.0.190",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@electron/rebuild": "^3.2.10",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
"displayName": "Continue",
|
||||
"pricing": "Free",
|
||||
"description": "The open-source coding autopilot",
|
||||
"version": "0.0.189",
|
||||
"version": "0.0.190",
|
||||
"publisher": "Continue",
|
||||
"engines": {
|
||||
"vscode": "^1.67.0"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue