-
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:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
What happened here? |
Beta Was this translation helpful? Give feedback.
-
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}") |
Beta Was this translation helpful? Give feedback.
-
Nvm, openai client has to configure proxy envs if you are behind a proxy... |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
Nvm, openai client has to configure proxy envs if you are behind a proxy...