Spaces:
Runtime error
Runtime error
hoshingakag
commited on
Commit
•
58c2aca
1
Parent(s):
00bd98a
added param, set temp
Browse files- app.py +9 -5
- src/llamaindex_palm.py +9 -3
app.py
CHANGED
@@ -73,10 +73,13 @@ def generate_chat(prompt: str, llamaindex_llm: LlamaIndexPaLM):
|
|
73 |
"framework": "Llama-Index",
|
74 |
"index_type": "VectorStoreIndex",
|
75 |
"vector_store": "Pinecone",
|
76 |
-
"
|
77 |
-
"
|
78 |
-
"
|
79 |
-
"
|
|
|
|
|
|
|
80 |
},
|
81 |
start_time_ms=start_time_ms,
|
82 |
end_time_ms=agent_end_time_ms,
|
@@ -108,7 +111,8 @@ def generate_chat(prompt: str, llamaindex_llm: LlamaIndexPaLM):
|
|
108 |
'category': genai.types.HarmCategory.HARM_CATEGORY_UNSPECIFIED,
|
109 |
'threshold': genai.types.HarmBlockThreshold.BLOCK_NONE,
|
110 |
},
|
111 |
-
]
|
|
|
112 |
)
|
113 |
result = response.result
|
114 |
success_flag = "success"
|
|
|
73 |
"framework": "Llama-Index",
|
74 |
"index_type": "VectorStoreIndex",
|
75 |
"vector_store": "Pinecone",
|
76 |
+
"vector_store_index": llamaindex_llm._index_name,
|
77 |
+
"vector_store_namespace": llamaindex_llm._index_namespace,
|
78 |
+
"model_name": llamaindex_llm.llm._model_name,
|
79 |
+
# "temperture": 0.7,
|
80 |
+
# "top_k": 40,
|
81 |
+
# "top_p": 0.95,
|
82 |
+
"custom_kwargs": llamaindex_llm.llm._model_kwargs,
|
83 |
},
|
84 |
start_time_ms=start_time_ms,
|
85 |
end_time_ms=agent_end_time_ms,
|
|
|
111 |
'category': genai.types.HarmCategory.HARM_CATEGORY_UNSPECIFIED,
|
112 |
'threshold': genai.types.HarmBlockThreshold.BLOCK_NONE,
|
113 |
},
|
114 |
+
],
|
115 |
+
temperature=0.9,
|
116 |
)
|
117 |
result = response.result
|
118 |
success_flag = "success"
|
src/llamaindex_palm.py
CHANGED
@@ -65,12 +65,14 @@ class LlamaIndexPaLMText(CustomLLM, extra=Extra.allow):
|
|
65 |
def __init__(
|
66 |
self,
|
67 |
model_name: str = 'models/text-bison-001',
|
|
|
68 |
context_window: int = 8196,
|
69 |
num_output: int = 1024,
|
70 |
**kwargs: Any,
|
71 |
) -> None:
|
72 |
super().__init__(**kwargs)
|
73 |
self._model_name = model_name
|
|
|
74 |
self._context_window = context_window
|
75 |
self._num_output = num_output
|
76 |
|
@@ -93,7 +95,8 @@ class LlamaIndexPaLMText(CustomLLM, extra=Extra.allow):
|
|
93 |
'category': genai.types.HarmCategory.HARM_CATEGORY_UNSPECIFIED,
|
94 |
'threshold': genai.types.HarmBlockThreshold.BLOCK_NONE,
|
95 |
},
|
96 |
-
]
|
|
|
97 |
)
|
98 |
logging.debug(f"response:\n{response}")
|
99 |
return response.candidates[0]['output']
|
@@ -155,12 +158,15 @@ class LlamaIndexPaLM():
|
|
155 |
|
156 |
def set_index_from_pinecone(
|
157 |
self,
|
158 |
-
index_name: str = 'experience'
|
|
|
159 |
) -> None:
|
160 |
# Pinecone VectorStore
|
161 |
pinecone_index = pinecone.Index(index_name)
|
162 |
-
self.vector_store = PineconeVectorStore(pinecone_index=pinecone_index, add_sparse_vector=True)
|
163 |
self.pinecone_index = VectorStoreIndex.from_vector_store(self.vector_store, self.service_context)
|
|
|
|
|
164 |
return None
|
165 |
|
166 |
def generate_response(
|
|
|
65 |
def __init__(
|
66 |
self,
|
67 |
model_name: str = 'models/text-bison-001',
|
68 |
+
model_kwargs: dict = {},
|
69 |
context_window: int = 8196,
|
70 |
num_output: int = 1024,
|
71 |
**kwargs: Any,
|
72 |
) -> None:
|
73 |
super().__init__(**kwargs)
|
74 |
self._model_name = model_name
|
75 |
+
self._model_kwargs = model_kwargs
|
76 |
self._context_window = context_window
|
77 |
self._num_output = num_output
|
78 |
|
|
|
95 |
'category': genai.types.HarmCategory.HARM_CATEGORY_UNSPECIFIED,
|
96 |
'threshold': genai.types.HarmBlockThreshold.BLOCK_NONE,
|
97 |
},
|
98 |
+
],
|
99 |
+
**self._model_kwargs
|
100 |
)
|
101 |
logging.debug(f"response:\n{response}")
|
102 |
return response.candidates[0]['output']
|
|
|
158 |
|
159 |
def set_index_from_pinecone(
|
160 |
self,
|
161 |
+
index_name: str = os.getenv('PINECONE_INDEX', 'experience'),
|
162 |
+
index_namespace: str = os.getenv('PINECONE_NAMESPACE', 'main')
|
163 |
) -> None:
|
164 |
# Pinecone VectorStore
|
165 |
pinecone_index = pinecone.Index(index_name)
|
166 |
+
self.vector_store = PineconeVectorStore(pinecone_index=pinecone_index, add_sparse_vector=True, namespace=index_namespace)
|
167 |
self.pinecone_index = VectorStoreIndex.from_vector_store(self.vector_store, self.service_context)
|
168 |
+
self._index_name = index_name
|
169 |
+
self._index_namespace = index_namespace
|
170 |
return None
|
171 |
|
172 |
def generate_response(
|