This commit is contained in:
Larfii
2024-10-07 18:48:45 +08:00
parent 13c67c2bcf
commit fba232487b
6 changed files with 152 additions and 5 deletions

View File

@@ -17,10 +17,9 @@ from .utils import compute_args_hash, wrap_embedding_func_with_attrs
retry=retry_if_exception_type((RateLimitError, APIConnectionError, Timeout)),
)
async def openai_complete_if_cache(
model, prompt, api_key=''
, system_prompt=None, history_messages=[], **kwargs
model, prompt, system_prompt=None, history_messages=[], **kwargs
) -> str:
openai_async_client = AsyncOpenAI(api_key=api_key)
openai_async_client = AsyncOpenAI()
hashing_kv: BaseKVStorage = kwargs.pop("hashing_kv", None)
messages = []
if system_prompt:
@@ -72,8 +71,8 @@ async def gpt_4o_mini_complete(
wait=wait_exponential(multiplier=1, min=4, max=10),
retry=retry_if_exception_type((RateLimitError, APIConnectionError, Timeout)),
)
async def openai_embedding(texts: list[str], api_key='') -> np.ndarray:
openai_async_client = AsyncOpenAI(api_key=api_key)
async def openai_embedding(texts: list[str]) -> np.ndarray:
openai_async_client = AsyncOpenAI()
response = await openai_async_client.embeddings.create(
model="text-embedding-3-small", input=texts, encoding_format="float"
)