forked from onlyphantom/llm-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05_hf.py
More file actions
33 lines (25 loc) · 1.03 KB
/
05_hf.py
File metadata and controls
33 lines (25 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from dotenv import load_dotenv
from langchain_huggingface import HuggingFaceEndpoint
from langchain_core.prompts import PromptTemplate
load_dotenv()
hub_llm = HuggingFaceEndpoint(repo_id="mrm8488/t5-base-finetuned-wikiSQL")
# prompt = PromptTemplate.from_template(
# "Translate English to SQL: {question}"
# )
# result = hub_llm.invoke(prompt.format(question="What is the average age of the respondents using a mobile device?"))
# print(result)
# second example below:
hub_llm = HuggingFaceEndpoint(
repo_id='distilgpt2',
task="text-generation",
temperature=0.7,
max_new_tokens=100
)
prompt = PromptTemplate.from_template(
"You had one job ! You're the {profession} and you didn't have to be sarcastic"
)
# Direct invocation with HuggingFaceEndpoint
print(hub_llm.invoke(prompt.format(profession="customer service agent")))
print(hub_llm.invoke(prompt.format(profession="politician")))
print(hub_llm.invoke(prompt.format(profession="Fintech CEO")))
print(hub_llm.invoke(prompt.format(profession="insurance agent")))