|
import gradio as gr |
|
from paperqa import Docs, SentenceTransformerEmbeddingModel |
|
from langchain_anthropic import ChatAnthropic |
|
|
|
MODEL_NAME = "claude-3-5-sonnet-20240620" |
|
class MyChatAnthropic(ChatAnthropic): |
|
model_name = MODEL_NAME |
|
llm = MyChatAnthropic( |
|
model=MODEL_NAME, |
|
temperature=0.2, |
|
max_tokens=4096,) |
|
|
|
class MyEmb(SentenceTransformerEmbeddingModel): |
|
async def aembed_documents(self, texts): |
|
return await self.embed_documents(None, texts) |
|
|
|
emb = MyEmb(model_name="mixedbread-ai/mxbai-embed-large-v1") |
|
docs = Docs(llm="langchain", |
|
embedding="langchain", |
|
embedding_client=emb, |
|
client=llm) |
|
docs.max_concurrent = 1 |
|
docs.add('knowledge_extraction.csv', disable_check=True) |
|
docs.add('SSA - POMS_ SI 00502.100 - Basic SSI Alien Eligibility Requirements - 11_30_2023.pdf', disable_check=True) |
|
|
|
def respond(message, *args, **kwargs): |
|
return docs.query(message).answer |
|
|
|
|
|
examples = [["A qualified alien entered the United States on August 15, 1996. Tell me about their eligibility for Supplemental Security Income (SSI)."], |
|
["""Question: Which of the following statements most accurately reflects the eligibility requirements for Supplemental Security Income (SSI) as outlined in the Alien Eligibility Under Welfare Reform? |
|
|
|
A) To be eligible for SSI, an individual must be a U.S. citizen, with no exceptions for non-citizens. |
|
|
|
B) SSI eligibility is extended to all individuals residing in the United States, regardless of their citizenship or immigration status. |
|
|
|
C) To be eligible for SSI, an individual must be either a U.S. citizen or a qualified alien. |
|
|
|
D) SSI eligibility is determined solely based on financial need, without consideration of citizenship or immigration status."""], |
|
["""Explanate the Correct Answer: C |
|
Question: Which of the following statements most accurately reflects the eligibility requirements for Supplemental Security Income (SSI) as outlined in the Alien Eligibility Under Welfare Reform? |
|
|
|
A) To be eligible for SSI, an individual must be a U.S. citizen, with no exceptions for non-citizens. |
|
|
|
B) SSI eligibility is extended to all individuals residing in the United States, regardless of their citizenship or immigration status. |
|
|
|
C) To be eligible for SSI, an individual must be either a U.S. citizen or a qualified alien. |
|
|
|
D) SSI eligibility is determined solely based on financial need, without consideration of citizenship or immigration status."""]] |
|
|
|
demo = gr.ChatInterface( |
|
respond, |
|
examples=examples) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch(auth=("tester", "8888p4ss")) |