zhu327 / gemini-openai-proxy

A proxy for converting the OpenAI API protocol to the Google Gemini Pro protocol.
MIT License
504 stars 92 forks source link

openai api : InternalServerError: Error code: 502 #12

Closed dorbodwolf closed 6 months ago

dorbodwolf commented 6 months ago

its work for curl

OPENAI_API_KEY="xxx" #google ai api
curl http://localhost:8080/v1/chat/completions   -H "Content-Type: application/json"   -H "Authorization: Bearer $OPENAI_API_KEY"   -d '{
    "model": "gpt-3.5-turbo",
    "messages": [
      {
        "role": "system",
        "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."
      },
      {
        "role": "user",
        "content": "Compose a poem that explains the concept of recursion in programming."
      }
    ]
  }'

but failed for python

from openai import OpenAI
client = OpenAI(api_key='xxx'
                , base_url='http://localhost:8080/v1/')

completion = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."},
    {"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."}
  ]
)

print(completion.choices[0].message)

the logs

File [~/anaconda3/envs/agents/lib/python3.9/site-packages/openai/_base_client.py:930](https://file+.vscode-resource.vscode-cdn.net/Users/jade_mayer/projects/agents/llamaindex/~/anaconda3/envs/agents/lib/python3.9/site-packages/openai/_base_client.py:930), in SyncAPIClient._request(self, cast_to, options, remaining_retries, stream, stream_cls)
    [927](https://file+.vscode-resource.vscode-cdn.net/Users/jade_mayer/projects/agents/llamaindex/~/anaconda3/envs/agents/lib/python3.9/site-packages/openai/_base_client.py:927)     if not err.response.is_closed:
    [928](https://file+.vscode-resource.vscode-cdn.net/Users/jade_mayer/projects/agents/llamaindex/~/anaconda3/envs/agents/lib/python3.9/site-packages/openai/_base_client.py:928)         err.response.read()
--> [930](https://file+.vscode-resource.vscode-cdn.net/Users/jade_mayer/projects/agents/llamaindex/~/anaconda3/envs/agents/lib/python3.9/site-packages/openai/_base_client.py:930)     raise self._make_status_error_from_response(err.response) from None
    [932](https://file+.vscode-resource.vscode-cdn.net/Users/jade_mayer/projects/agents/llamaindex/~/anaconda3/envs/agents/lib/python3.9/site-packages/openai/_base_client.py:932) return self._process_response(
    [933](https://file+.vscode-resource.vscode-cdn.net/Users/jade_mayer/projects/agents/llamaindex/~/anaconda3/envs/agents/lib/python3.9/site-packages/openai/_base_client.py:933)     cast_to=cast_to,
    [934](https://file+.vscode-resource.vscode-cdn.net/Users/jade_mayer/projects/agents/llamaindex/~/anaconda3/envs/agents/lib/python3.9/site-packages/openai/_base_client.py:934)     options=options,
   (...)
    [937](https://file+.vscode-resource.vscode-cdn.net/Users/jade_mayer/projects/agents/llamaindex/~/anaconda3/envs/agents/lib/python3.9/site-packages/openai/_base_client.py:937)     stream_cls=stream_cls,
    [938](https://file+.vscode-resource.vscode-cdn.net/Users/jade_mayer/projects/agents/llamaindex/~/anaconda3/envs/agents/lib/python3.9/site-packages/openai/_base_client.py:938) )

InternalServerError: Error code: 502
zhu327 commented 6 months ago
In [1]: from openai import OpenAI

In [2]: client = OpenAI(api_key='xxx'
   ...:                 , base_url='http://localhost:8080/v1/')

In [3]: completion = client.chat.completions.create(
   ...:   model="gpt-3.5-turbo",
   ...:   messages=[
   ...:     {"role": "system", "content": "You are a poetic assistant, skilled in explaining complex programming concept
   ...: s with creative flair."},
   ...:     {"role": "user", "content": "Compose a poem that explains the concept of recursion in programming."}
   ...:   ]
   ...: )

In [4]: print(completion.choices[0].message)
ChatCompletionMessage(content="In the realm of code, where logic flows,\nRecursion's tale my muse now knows.\nA function calls upon its own embrace,\nIn a self-referential, looping chase.\n\nLike echoes in a hall of mirrors vast,\nRecursion's power does surpass.\nIt breaks the task to smaller seeds,\nUntil the simplest form it breeds.\n\nThe base case stands, a beacon bright,\nWhere recursion's journey comes to light.\nIt marks the end, the task's completion,\nA moment of computational fruition.\n\nAs each recursive call unfurled,\nThe stack, a tower, holds the world.\nLike nested dolls, they fit so tight,\nEach level's purpose shining bright.\n\nAnd when the base case finally nears,\nThe stack unwinds, dispelling fears.\nResults cascade, like raindrops pure,\nUnveiling answers, problems cured.\n\nRecursion, a tool both sharp and keen,\nIts elegance in code is clearly seen.\nIt's a dance of functions, twirling free,\nUnraveling complexities with glee.\n\nSo let us revel in recursion's might,\nIts power to solve, a wondrous sight.\nFor in this recursive realm, we find,\nA world of logic, intertwined.", role='assistant', function_call=None, tool_calls=None)

I tried it and there is no problem, you need to check your network status