Spaces:
Paused

MEOW commited on
Commit
7b9f359
·
unverified ·
1 Parent(s): b93c0b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -12,7 +12,7 @@ logging.basicConfig(level=logging.INFO)
12
  logger = logging.getLogger(__name__)
13
 
14
  # Assuming xAI provides their endpoint for generating text
15
- XAI_API_URL = "https://api.x.ai/v1/chat/completions"
16
 
17
  # Custom LLM class for xAI
18
  class XAILLM:
@@ -38,7 +38,7 @@ Settings.llm = XAILLM()
38
  class XAIEmbedding:
39
  def __init__(self):
40
  self.api_key = os.getenv('XAI_API_KEY')
41
- self.model_id = "v1"
42
 
43
  def get_text_embedding(self, text):
44
  headers = {
@@ -49,9 +49,17 @@ class XAIEmbedding:
49
  "input": text,
50
  "model": self.model_id
51
  }
52
- response = requests.post("xAI's embed endpoint URL", headers=headers, json=data)
53
  response.raise_for_status()
54
- return response.json()['data'][0]['embedding'] # Adjust based on xAI's API response structure
 
 
 
 
 
 
 
 
55
 
56
  Settings.embed_model = XAIEmbedding()
57
  Settings.text_splitter = SentenceSplitter(chunk_size=400)
 
12
  logger = logging.getLogger(__name__)
13
 
14
  # Assuming xAI provides their endpoint for generating text
15
+ XAI_API_URL = "https://api.x.ai/v1/embeddings"
16
 
17
  # Custom LLM class for xAI
18
  class XAILLM:
 
38
  class XAIEmbedding:
39
  def __init__(self):
40
  self.api_key = os.getenv('XAI_API_KEY')
41
+ self.model_id = "v1" # Adjust as per xAI's model ID
42
 
43
  def get_text_embedding(self, text):
44
  headers = {
 
49
  "input": text,
50
  "model": self.model_id
51
  }
52
+ response = requests.post(XAI_API_URL, headers=headers, json=data)
53
  response.raise_for_status()
54
+ return response.json()['data'][0]['embedding']
55
+
56
+ def get_text_embedding_batch(self, texts):
57
+ # This method will handle batch requests
58
+ embeddings = []
59
+ for text in texts:
60
+ embedding = self.get_text_embedding(text)
61
+ embeddings.append(embedding)
62
+ return embeddings
63
 
64
  Settings.embed_model = XAIEmbedding()
65
  Settings.text_splitter = SentenceSplitter(chunk_size=400)