Repository navigation
|
I just started using from openai import OpenAI
client = OpenAI(api_key="EMPTY", base_url="http://local-ip:7997/v1")
try:
response = client.embeddings.create(
model="models/bge-m3",
input=["the sound of a beep", "the sound of a cat"],
encoding_format="float",
extra_body={"modality": "text"},
)
print(response)
except Exception as e:
print(f"An error occurred: {e}")And my package info: and my error message: |
Answered by
liux2
Nov 22, 2024
Replies: 4 comments 1 reply
|
What happened here? |
0 replies
|
More details: relevant code: from openai import OpenAI
from openai.types.create_embedding_response import CreateEmbeddingResponse
from openai.types import EmbeddingCreateParams
import json
from pprint import pprint
from typing import get_type_hints
# Define the actual API schema from curl command
ACTUAL_API_SCHEMA = {
"model": "models/bge-m3",
"encoding_format": "float",
"user": "string",
"input": ["string"],
"modality": "text"
}
# Get OpenAI client schema
openai_params = get_type_hints(EmbeddingCreateParams)
print("\nOpenAI Client Schema:")
pprint(openai_params)
print("\nActual API Schema (from curl):")
pprint(ACTUAL_API_SCHEMA)
# Compare differences
print("\nAnalysis of differences:")
openai_keys = set(openai_params.keys())
actual_keys = set(ACTUAL_API_SCHEMA.keys())
print("\nFields only in OpenAI client:")
pprint(openai_keys - actual_keys)
print("\nFields only in actual API:")
pprint(actual_keys - openai_keys)
print("\nCommon fields:")
pprint(openai_keys & actual_keys)
# Test both schemas
client = OpenAI(api_key="EMPTY", base_url="http://local-ip:7997/v1")
print("\nTesting with OpenAI client schema:")
try:
response1 = client.embeddings.create(
model="models/bge-m3",
input=["test string"],
encoding_format="float",
extra_body={"modality": "text"} # Note: modality needs to be passed as extra_body
)
print("OpenAI client request successful")
except Exception as e:
print(f"OpenAI client error: {e}")
print("\nTesting with actual API schema:")
import requests
try:
response2 = requests.post(
"http://local-ip:7997/v1/embeddings",
headers={
"accept": "application/json",
"Content-Type": "application/json"
},
json=ACTUAL_API_SCHEMA
)
print(f"Direct request status: {response2.status_code}")
except Exception as e:
print(f"Direct request error: {e}") |
0 replies
|
Nvm, openai client has to configure proxy envs if you are behind a proxy... |
0 replies
Answer selected by
liux2
|
Seems like your IP is weird, makes sense you solved it with the proxy. You would see in the fast app logs if the server would respond with 502 error. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nvm, openai client has to configure proxy envs if you are behind a proxy...