-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DST-199: base code for chunking #24
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
eec0438
replace 3.5 with 4o and use gemini flash 1.5
ccheng26 fa8961b
format
ccheng26 61b4fd0
set up chunking function
ccheng26 6b34a5b
refactor to not instantiate with every message call
ccheng26 6930520
create function for stuffing code
ccheng26 93af4ab
implement chunking code
ccheng26 11e9db1
fix instantiation err
ccheng26 26a079a
refactor llm choices into class
ccheng26 94fbc1b
update stuffing code
ccheng26 460fc09
get client call for responses
ccheng26 920ab0a
formatted
ccheng26 89e7171
fixes to gemini model default
ccheng26 f5b6044
rename function call
ccheng26 14b9f68
Merge branch 'main' of github.com:navapbc/labs-gen-ai-experiments int…
ccheng26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
from langchain_text_splitters import ( | ||
RecursiveCharacterTextSplitter, | ||
NLTKTextSplitter, | ||
SpacyTextSplitter, | ||
) | ||
from langchain_core.prompts import PromptTemplate | ||
from langchain.docstore.document import Document | ||
from llm import LLM | ||
from run import get_transcript | ||
|
||
|
||
# split text into chunks | ||
def get_text_chunks(text, chunk_size, chunk_overlap, text_splitter_choice): | ||
if text_splitter_choice == "2": | ||
text_splitter = NLTKTextSplitter() | ||
elif text_splitter_choice == "3": | ||
text_splitter = SpacyTextSplitter() | ||
else: | ||
text_splitter = RecursiveCharacterTextSplitter( | ||
chunk_size=chunk_size, chunk_overlap=chunk_overlap | ||
) | ||
|
||
texts = text_splitter.split_text(text) | ||
|
||
docs = [ | ||
Document( | ||
page_content=t, | ||
) | ||
for t in texts | ||
] | ||
|
||
return docs | ||
|
||
|
||
CHUNKING_PROMPT = """ | ||
You are a helpful AI assistant tasked with summarizing transcripts, however we can only process the transcripts in pieces. | ||
Fill out the fields with the text given {text}. If the following template already has the field filled out, do not overwrite this information. | ||
Please fill out the data with the following template: {template} | ||
""" | ||
|
||
initial_temp = """ | ||
1. Caller Information: | ||
- Name | ||
- Contact Information | ||
- Availability | ||
- Household Information | ||
2. Reason/Type of Call: e.g., Applying for benefits, Follow-ups | ||
3. Previous Benefits History: | ||
- Applied for | ||
- Receives | ||
- Denied | ||
4. Benefits Discussion: Prefix the discussed benefit with a hashtag (e.g., #SNAP, #LIHEAP) | ||
5. Discussion Points: | ||
- Key information points | ||
6. Documents Needed: e.g., Income verification, Housing documentation | ||
7. Next Steps for Client | ||
8. Next Steps for Agent | ||
""" | ||
|
||
|
||
def chunking_ingest(transcript, prompt): | ||
text_chunks = get_text_chunks( | ||
transcript, chunk_size=750, chunk_overlap=300, text_splitter_choice="2" | ||
) | ||
prompt_template = PromptTemplate.from_template(prompt) | ||
template = initial_temp | ||
ccheng26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
print(""" | ||
Select an llm | ||
1. openhermes (default) | ||
2. dolphin | ||
3. gemini | ||
4. gpt 4 | ||
5. gpt 4o | ||
6. claude 3 | ||
""") | ||
|
||
llm = input() or "1" | ||
|
||
if llm == "2": | ||
client = LLM(client_name="ollama", model_name="dolphin-mistral") | ||
print("""---------- | ||
Dolphin | ||
""") | ||
|
||
elif llm == "3": | ||
client = LLM(client_name="gemini") | ||
print("""---------- | ||
Gemini Flash 1.5 | ||
""") | ||
elif llm == "4": | ||
print("""---------- | ||
GPT 4 | ||
""") | ||
client = LLM(client_name="gpt", model_name="gpt4") | ||
elif llm == "5": | ||
print("""---------- | ||
GPT 4o | ||
""") | ||
client = LLM(client_name="gpt", model_name="gpt-4o") | ||
elif llm == "6": | ||
print("""---------- | ||
Claude 3 | ||
""") | ||
client = LLM(client_name="claude") | ||
else: | ||
print(""" | ||
Openhermes | ||
""") | ||
client = LLM(client_name="ollama", model_name="openhermes") | ||
|
||
client.get_client() | ||
for text in text_chunks: | ||
formatted_prompt = prompt_template.format( | ||
text=text.page_content, template=template | ||
) | ||
print("Processing Text Chunk") | ||
template = client.generate_text(prompt=formatted_prompt) | ||
print("Complete") | ||
return template | ||
|
||
|
||
if __name__ == "__main__": | ||
print(chunking_ingest(transcript=get_transcript(), prompt=CHUNKING_PROMPT)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the current code always uses
"2"
, so the chunk_size and chunk_overlap are not used.