mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-07 14:03:26 +00:00
LLaMA2 with JSON schema support template (#12435)
This commit is contained in:
3
templates/llama2-functions/llama2_functions/__init__.py
Normal file
3
templates/llama2-functions/llama2_functions/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from llama2_functions.chain import chain
|
||||
|
||||
__all__ = ["chain"]
|
47
templates/llama2-functions/llama2_functions/chain.py
Normal file
47
templates/llama2-functions/llama2_functions/chain.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from langchain.chat_models import ChatOpenAI
|
||||
from langchain.llms import Replicate
|
||||
from langchain.prompts import ChatPromptTemplate
|
||||
|
||||
# LLM
|
||||
replicate_id = "andreasjansson/llama-2-13b-chat-gguf:60ec5dda9ff9ee0b6f786c9d1157842e6ab3cc931139ad98fe99e08a35c5d4d4" # noqa: E501
|
||||
model = Replicate(
|
||||
model=replicate_id,
|
||||
model_kwargs={"temperature": 0.8,
|
||||
"max_length": 500,
|
||||
"top_p": 0.95},
|
||||
)
|
||||
|
||||
# Prompt with output schema specification
|
||||
template = """A article will be passed to you. Extract from it all papers that are mentioned by this article.
|
||||
|
||||
Do not extract the name of the article itself. If no papers are mentioned that's fine - you don't need to extract any! Just return an empty list.
|
||||
|
||||
Do not make up or guess ANY extra information. Only extract what exactly is in the text.
|
||||
|
||||
Respond with json that adheres to the following jsonschema:
|
||||
|
||||
{{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {{
|
||||
"author": {{
|
||||
"type": "string",
|
||||
"description": "The author of the paper."
|
||||
}},
|
||||
"title": {{
|
||||
"type": "string",
|
||||
"description": "The title of the paper."
|
||||
}}
|
||||
}},
|
||||
"required": ["author", "title"],
|
||||
"additionalProperties": false
|
||||
}}""" # noqa: E501
|
||||
|
||||
prompt = ChatPromptTemplate.from_messages([("system", template), ("human", "{input}")])
|
||||
|
||||
# Chain
|
||||
model = ChatOpenAI()
|
||||
chain = (
|
||||
prompt
|
||||
| model
|
||||
)
|
Reference in New Issue
Block a user