-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(langchain): improve generation_info and llm outputs
Signed-off-by: Tomas Dvorak <toomas2d@gmail.com>
- Loading branch information
Showing
12 changed files
with
341 additions
and
118 deletions.
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
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,34 @@ | ||
import os | ||
|
||
from dotenv import load_dotenv | ||
from langchain.evaluation import EvaluatorType, load_evaluator | ||
|
||
from genai.credentials import Credentials | ||
from genai.extensions.langchain import LangChainChatInterface | ||
from genai.schemas import GenerateParams | ||
|
||
# make sure you have a .env file under genai root with | ||
# GENAI_KEY=<your-genai-key> | ||
load_dotenv() | ||
api_key = os.getenv("GENAI_KEY", None) | ||
api_endpoint = os.getenv("GENAI_API", None) | ||
credentials = Credentials(api_key, api_endpoint=api_endpoint) | ||
|
||
# Load a trajectory (conversation) evaluator | ||
llm = LangChainChatInterface( | ||
model="meta-llama/llama-2-70b-chat", | ||
credentials=credentials, | ||
params=GenerateParams( | ||
decoding_method="sample", | ||
min_new_tokens=1, | ||
max_new_tokens=100, | ||
length_penalty={ | ||
"decay_factor": 1.5, | ||
"start_index": 50, | ||
}, | ||
temperature=1.2, | ||
stop_sequences=["<|endoftext|>", "}]"], | ||
), | ||
) | ||
evaluator = load_evaluator(evaluator=EvaluatorType.AGENT_TRAJECTORY, llm=llm) | ||
print(evaluator) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
|
||
from dotenv import load_dotenv | ||
from llama_index.llms import LangChainLLM | ||
|
||
from genai import Credentials | ||
from genai.extensions.langchain import LangChainInterface | ||
from genai.schemas import GenerateParams | ||
|
||
load_dotenv() | ||
api_key = os.environ.get("GENAI_KEY") | ||
api_url = os.environ.get("GENAI_API") | ||
langchain_model = LangChainInterface( | ||
model="meta-llama/llama-2-70b-chat", | ||
credentials=Credentials(api_key, api_endpoint=api_url), | ||
params=GenerateParams( | ||
decoding_method="sample", | ||
min_new_tokens=1, | ||
max_new_tokens=10, | ||
), | ||
) | ||
|
||
llm = LangChainLLM(llm=langchain_model) | ||
response_gen = llm.stream_chat("What is a molecule?") | ||
for delta in response_gen: | ||
print(delta.delta) |
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.