Skip to content

Commit

Permalink
book
Browse files Browse the repository at this point in the history
  • Loading branch information
weitsung50110 committed Dec 12, 2024
1 parent 1686c7d commit db58482
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions agents/langchain_agents_conversational-react_memory-Vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def get_today_date(_):
tools=tools,
llm=llm,
agent="conversational-react-description", # 使用對話型代理
verbose=False,
verbose=False, #控制是否顯示詳細的調試信息
agent_prompt=custom_prompt,
handle_parsing_errors=True,
handle_parsing_errors=True, #啟用錯誤處理
memory=memory
)

Expand Down
23 changes: 23 additions & 0 deletions book/langchain_sys_SEOtitle_article_generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 用LangChain使mistral:7b-instruct-q2_K藉由對話生成文章和SEO標題,把語言模型變成愛情作家之教學

from langchain_community.llms import Ollama
from langchain_core.prompts import ChatPromptTemplate
from langchain.callbacks.manager import CallbackManager
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

# 如果加上了CallbackManager就可以即時看到llm生成的文字,
# 若沒加CallbackManager則是要等到llm把文字全部生成完成後 才會顯示出來

llm = Ollama(model='mistral:7b-instruct-q2_K', callback_manager=CallbackManager([StreamingStdOutCallbackHandler()]))

prompt = ChatPromptTemplate.from_messages([
("system", "You are a love story creator with extensive SEO knowledge. Your task is to write an article with about 100 words, and create a SEO title for the article you wrote."),
("user", "{input}"),
])

# print(prompt)

chain = prompt | llm
chain.invoke({"input": input('>>> ')})

#輸入文字後,會依據文字生成SEO標題 和 文章內容

0 comments on commit db58482

Please sign in to comment.