藉由免費Groq API服務,橋接使用臉書Meta開放源碼LLM大語言模型,進行 日文相關查詢運用
💜步驟一:
☺💟https://console.groq.com/keys 取得API KEY
☺💟在自己的電腦環境變數,加入GROQ_API_KEY變數,指定您所取得API KEY值
💜步驟二: 備妥PYTHON執行環境
pip install groq
💜步驟三:將下面藍色部分,另存成 PYTHON程式碼(如:testgroq.py ),並且執行它即可
import os
from groq import Groq
client = Groq(
api_key=os.environ.get("GROQ_API_KEY"),
)
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content":
"あなたは日本語のプロで、勉強法の達人です。 {{関連表現}}の語源は教えて、漢字ははっきりとはしないが、省略しても構いません。 {{関連表現}}の文法解説・例文と類義語を簡潔な概要でまとめてください。もし、その表現はニュアンス、意志、自発、あるいは自分、他の人、その他の表現などに関連があれば、使い方を教えて暗記しやすいように、その他の類義表現文型と違いところを表形式に挙げてください。それぞれの表現に焦点を当てたYOUTUBE動画を挙げてください 関連表現: かたがた、を兼ねて、ついで、がてら、かたわら ",
}
],
model="Llama3-70b-8192",
)
print(chat_completion.choices[0].message.content)
相關資訊:
Japanese relationship learning日文相關連關鍵資訊查詢,增進廣度面向之學習。
💛後記:測試結果,取得YOUTUBE連結不能使用,可能持續MachineLearning學習中?
此種查詢傳遞方式,仍需留意資料是否含機敏資訊?
💛Temperature Control: (可於程式碼中 ,在model="Llama3-70b-8192"上方,加入 temperature = 0.1 ,不加溫度參數效果較好)A lower temperature results in more deterministic and focused responses, while a higher temperature increases diversity and explores more unconventional possibilities
💛檔名請勿以 groq.py 命名,否則會出現下面錯誤訊息 👀
ImportError: cannot import name 'Groq' from partially initialized module 'groq' (most likely due to a circular import)
💙回傳結果如下:
**1. かたがた (katagata)**
Meaning: and so on, and other things like that
(略)
Example sentence: 私のかたがた、運動ですか? (Watashi no katagata, undō desu ka? - Are you doing exercise and other things like that?)
**2. を兼ねて (o kane te)**
Meaning: while doing, simultaneously
(略)
Example sentence: 私は仕事を兼ねて、ユーチューブを見ています (Watashi wa shigoto o kane te, Yūchūbu o mite imasu - I'm watching YouTube while working)
**3. ついで (tsuide)**
Meaning: by the way, while I'm at it
(略)
Example sentence: 私は店についで、雑貨を買います (Watashi wa mise ni tsuide, zakka o kaimasu - I'll buy some miscellaneous goods while I'm at the store)
**4. がてら (gatera)**
Meaning: and other things, et cetera
(略)
Example sentence: 私は料理がてら、健康について学びます (Watashi wa ryōri gatera, kenkō ni tsuite gakushū shimasu - I'll learn about cooking and other things, like health)
**5. かたわら (katawara)**
- This word means "on the side" or "in addition to."
* Example: 「私は本業のかたわら、フリーランスの仕事もしています」(In addition to my main job, I also do freelance work on the side.)
(略)
參考資訊:
https://console.groq.com/docs/quickstart
'#####################################################################
💛動態傳遞參數範例1: 使用方式 python testgroq.py 您提問的問題
#placeholder text from the dynamic value (sys.argv[1])
import os
import sys
from groq import Groq
client = Groq(
api_key=os.environ.get("GROQ_API_KEY"),
)
# Get the dynamic expression from sys.argv[1]
dynamic_expression = sys.argv[1]
# Replace the placeholder text with the dynamic expression
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": f"{dynamic_expression}",
}
],
model="Llama3-70b-8192",
)
# Print the generated response
print(chat_completion.choices[0].message.content)
'#####################################################################
💛動態傳遞參數範例2: 將常用的詢問(日文文法查詢)預先作好Prompt樣版,只要將您詢問參數代入,即可查詢
python testgroq.py 如し、如く、如き
#placeholder text from the dynamic value (sys.argv[1])
import os
import sys
from groq import Groq
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
# Get the dynamic expression from sys.argv[1]
dynamic_expression = sys.argv[1]
# Construct the message content with the dynamic expression
user_message = {
"role": "user",
"content": f"あなたは日本語のプロで、勉強法の達人です。日本語の文法を徹底解説してください。例えば:文型、ニュアンス、図表、例文(専門家向け)下記の問題を徹底ステップバイステップ解説してください: {dynamic_expression}",
}
# Generate completion using Groq API
chat_completion = client.chat.completions.create(
messages=[user_message],
model="Llama3-70b-8192",
)
# Extract and print the generated response
generated_response = chat_completion.choices[0].message.content
print(generated_response)
💙回傳結果如下:
What an honor to delve into the intricacies of Japanese grammar!
**如し (nashi)** (小BUG錯誤🚨 ,正確應該 gotosi)
* Usage: Used to describe a comparison or analogy, often with a sense of similarity or resemblance.
* Example sentences:
(略)
+ 彼の顔は如し私の叔父のように見える (Kare no kao wa nashi watashi no oji no you ni mieru) - His face looks like my uncle's. 小BUG錯誤🚨終止形,詞性屬⌈文言比況助動詞⌋,通常放句尾,相當於ようだ
**如き (ki)**
* Usage: Used to describe a hypothetical or imaginary situation, often with a sense of uncertainty or tentativeness.
* Example sentences:
+ 私は如き億万長者のように生活している (Watashi wa ki no okuman chōja no you ni seikatsu shite iru) - I'm living as if I were a billionaire. 🚨連体形,相當於ような
(略)
**如く (ku)**
* Usage: Used to describe a manner or method of doing something, often with a sense of following a model or example.
* Example sentences:
(略)
+ 彼は如く名選手のように野球をプレイする (Kare wa ku mei senshu no you ni yakyū o purei suru) - He plays baseball like a famous player. 🚨連用形,相當於ように
(略)