Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
# -- Libraries
|
| 3 |
from typing import Any, Dict, List, Mapping, Optional
|
| 4 |
from pydantic import Extra, Field, root_validator
|
|
|
|
| 5 |
from langchain_core.runnables import RunnablePassthrough
|
| 6 |
from langchain.llms.base import LLM
|
| 7 |
from langchain.chat_models import ChatOpenAI
|
|
@@ -199,29 +200,32 @@ def get_gpt_response(transcription_path, query, logger):
|
|
| 199 |
| StrOutputParser()
|
| 200 |
)
|
| 201 |
llm_output = rag_chain.invoke(query)
|
| 202 |
-
# dataset = client.create_dataset(dataset_name="Sample LLM dataset", description="A dataset with LLM inputs and outputs", data_type="llm")
|
| 203 |
-
|
| 204 |
-
# client.create_example(
|
| 205 |
-
# inputs={"input": query},
|
| 206 |
-
# outputs={"output": llm_output},
|
| 207 |
-
# dataset_id=dataset.id,
|
| 208 |
-
# )
|
| 209 |
-
|
| 210 |
-
# -- Run custom evaluator
|
| 211 |
-
# evaluation_config = RunEvalConfig(
|
| 212 |
-
# custom_evaluators = [RelevanceEvaluator()],
|
| 213 |
-
# )
|
| 214 |
-
# eval_output = run_on_dataset(
|
| 215 |
-
# dataset_name="Sample LLM dataset",
|
| 216 |
-
# llm_or_chain_factory=rag_chain,
|
| 217 |
-
# evaluation=evaluation_config,
|
| 218 |
-
# client=client,
|
| 219 |
-
# )
|
| 220 |
-
# logger.info("Eval output!!!!")
|
| 221 |
-
# logger.info(eval_output)
|
| 222 |
-
|
| 223 |
return llm_output
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
# -- Text summarisation with OpenAI (map-reduce technique)
|
| 226 |
def summarise_doc(transcription_path, model_name, model=None):
|
| 227 |
if model_name == 'gpt':
|
|
|
|
| 2 |
# -- Libraries
|
| 3 |
from typing import Any, Dict, List, Mapping, Optional
|
| 4 |
from pydantic import Extra, Field, root_validator
|
| 5 |
+
from langchain_community.vectorstores import FAISS
|
| 6 |
from langchain_core.runnables import RunnablePassthrough
|
| 7 |
from langchain.llms.base import LLM
|
| 8 |
from langchain.chat_models import ChatOpenAI
|
|
|
|
| 200 |
| StrOutputParser()
|
| 201 |
)
|
| 202 |
llm_output = rag_chain.invoke(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
return llm_output
|
| 204 |
|
| 205 |
+
def get_character_info_gpt(text, character):
|
| 206 |
+
vectorstore = FAISS.from_texts(
|
| 207 |
+
[text], embedding=OpenAIEmbeddings()
|
| 208 |
+
)
|
| 209 |
+
retriever = vectorstore.as_retriever()
|
| 210 |
+
|
| 211 |
+
template = """Responde a la siguiente pregunta basandote unicamente en el siguiente contexto:
|
| 212 |
+
{context}
|
| 213 |
+
|
| 214 |
+
Pregunta: {question}
|
| 215 |
+
"""
|
| 216 |
+
prompt = ChatPromptTemplate.from_template(template)
|
| 217 |
+
|
| 218 |
+
model = ChatOpenAI()
|
| 219 |
+
|
| 220 |
+
chain = (
|
| 221 |
+
{"context": retriever, "question": RunnablePassthrough()}
|
| 222 |
+
| prompt
|
| 223 |
+
| model
|
| 224 |
+
| StrOutputParser()
|
| 225 |
+
)
|
| 226 |
+
return chain.invoke("¿Quien es {}?".format(character))
|
| 227 |
+
|
| 228 |
+
|
| 229 |
# -- Text summarisation with OpenAI (map-reduce technique)
|
| 230 |
def summarise_doc(transcription_path, model_name, model=None):
|
| 231 |
if model_name == 'gpt':
|