Skip to content
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

LlamaPacks: Add memary llamapack #13968

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
58ce34b
init: first package
seyeong-han Jun 5, 2024
4c62740
docs: add llamahub info
seyeong-han Jun 6, 2024
f6c6db1
docs: versioning python and memary
seyeong-han Jun 6, 2024
d878bd0
docs: author's info
seyeong-han Jun 6, 2024
69dff3e
docs: add poetry dependencies
seyeong-han Jun 6, 2024
054c71f
init: first README
seyeong-han Jun 6, 2024
4d710f9
init: first memary/agent
seyeong-han Jun 6, 2024
ceef367
init: first memary/memory
seyeong-han Jun 6, 2024
7f6e32c
init: first memary/synonym_expand
seyeong-han Jun 6, 2024
b25fdf3
init: memory module tests for pytest
seyeong-han Jun 6, 2024
fc284d1
init: memory module tests for pytest
seyeong-han Jun 6, 2024
7fd8c50
init: streamlit example
seyeong-han Jun 6, 2024
577f4e2
init: memary __init__.py
seyeong-han Jun 6, 2024
d75312c
init: first agent/llm_api
seyeong-han Jun 6, 2024
9919418
refactor: run `make lint`
seyeong-han Jun 7, 2024
f5d3b4c
fix: add target sources
seyeong-han Jun 7, 2024
495ea8a
fix: add poetry_requirements after running `pants tailor`
seyeong-han Jun 12, 2024
aefa471
refactor: remove and replace with memary library
seyeong-han Jun 17, 2024
8318047
refactor: follow dependencies with memary library
seyeong-han Jun 17, 2024
5057b8f
init: add MemaryChatAgentPack as base
seyeong-han Jun 17, 2024
2e4cfba
refactor: import MemaryChatAgentPack only
seyeong-han Jun 17, 2024
fa57662
refactor: add test_class
seyeong-han Jun 17, 2024
ac5e65e
refactor: rename ChatAgent to MemaryChatAgentPack
seyeong-han Jun 17, 2024
bdd97bc
build files
logan-markewich Jun 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
init: first memary/synonym_expand
  • Loading branch information
seyeong-han committed Jun 6, 2024
commit 7f6e32cd01de8c1cda9879639b91198a948d31ff
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from llama_index.packs.memary.synonym_expand.synonym import custom_synonym_expand_fn
from llama_index.packs.memary.synonym_expand.output import SynonymOutput

__all__ = ["custom_synonym_expand_fn", "SynonymOutput"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import List

from langchain_core.pydantic_v1 import BaseModel, Field


class SynonymOutput(BaseModel):
synonyms: List[str] = Field(
description=
"Synonyms of keywords provided, make every letter lowercase except for the first letter"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from langchain_openai import OpenAI
from langchain.prompts import PromptTemplate
from langchain_core.output_parsers import JsonOutputParser
from typing import List
import os
from llama_index.packs.memary.synonym_expand.output import SynonymOutput
from dotenv import load_dotenv


def custom_synonym_expand_fn(keywords: str) -> List[str]:
load_dotenv()
llm = OpenAI(openai_api_key=os.getenv("OPENAI_KEY"), temperature=0)
parser = JsonOutputParser(pydantic_object=SynonymOutput)

template = """
You are an expert synonym exapnding system. Find synonyms or words commonly used in place to reference the same word for every word in the list:

Some examples are:
- a synonym for Palantir may be Palantir technologies or Palantir technologies inc.
- a synonym for Austin may be Austin texas
- a synonym for Taylor swift may be Taylor
- a synonym for Winter park may be Winter park resort

Format: {format_instructions}

Text: {keywords}
"""

prompt = PromptTemplate(
template=template,
input_variables=["keywords"],
partial_variables={
"format_instructions": parser.get_format_instructions()
},
)

chain = prompt | llm | parser
result = chain.invoke({"keywords": keywords})

l = []
for category in result:
for synonym in result[category]:
l.append(synonym.capitalize())

return l


# testing
# print(custom_synonym_expand_fn("[Nvidia]"))