-
Notifications
You must be signed in to change notification settings - Fork 3
/
anthropic_llm.py
26 lines (21 loc) · 827 Bytes
/
anthropic_llm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import logging
log = logging.getLogger('app.llm')
def llm(model):
model= "command" if model is None else model
log.info(f"using model: {model}")
api_key = os.getenv("API_KEY")
if api_key is None:
raise Exception('API_KEY not found in environment')
from llama_index.llms.anthropic import Anthropic
anthropic = Anthropic(api_key=api_key,model=model)
return anthropic
def embed_llm(model):
model= "voyage-2" if model is None else model
log.info(f"using embed model: {model}")
api_key = os.getenv("EMBED_API_KEY")
if api_key is None:
raise Exception('EMBED_API_KEY not found in environment')
from llama_index.embeddings.voyageai import VoyageEmbedding
voyage_embed = VoyageEmbedding(voyage_api_key=api_key,model_name= model)
return voyage_embed