(texts: list[str])
| 29 | TOTAL_API_CALL_COST = 0 |
| 30 | |
| 31 | def embedding(texts: list[str]) -> np.ndarray: |
| 32 | model_name = EMBEDDING_MODEL |
| 33 | client = OpenAI( |
| 34 | api_key=EMBEDDING_MODEL, |
| 35 | base_url=EMBEDDING_URL |
| 36 | ) |
| 37 | embedding = client.embeddings.create( |
| 38 | input=texts, |
| 39 | model=model_name, |
| 40 | ) |
| 41 | final_embedding = [d.embedding for d in embedding.data] |
| 42 | return np.array(final_embedding) |
| 43 | |
| 44 | tokenizer = tiktoken.get_encoding("cl100k_base") |
| 45 | def truncate_text(text, max_tokens=4096): |