Skip to content

Commit

Permalink
modified: yuisub/llm.py
Browse files Browse the repository at this point in the history
	modified:   yuisub/prompt.py
  • Loading branch information
NULL204 committed Feb 6, 2025
1 parent c64e91f commit d4a9078
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
11 changes: 6 additions & 5 deletions yuisub/llm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from typing import Optional

import openai
Expand Down Expand Up @@ -34,15 +33,17 @@ async def ask(self, question: ORIGIN) -> ZH:

messages = [
{"role": "system", "content": self.system_prompt},
{"role": "user", "content": question.model_dump_json()},
{"role": "user", "content": question.origin},
]

try:
response = await self.client.chat.completions.create(
model=self.model, messages=messages, response_format={"type": "json_object"}
model=self.model,
messages=messages,
)
content = json.loads(response.choices[0].message.content)
zh = ZH(**content)

zh_text = response.choices[0].message.content
zh = ZH(zh=zh_text.strip())

except openai.AuthenticationError as e:
print(f"Authentication Error: {e} retrying...")
Expand Down
24 changes: 8 additions & 16 deletions yuisub/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ def anime_prompt(bangumi_info: Optional[BGM] = None, summary: str = "") -> str:
+ """
EXAMPLE INPUT:
{
"origin": "止まるんじゃねぇぞ!"
}
EXAMPLE JSON OUTPUT:
{
"zh": "不要停下来啊!"
}
止まるんじゃねぇぞ!
EXAMPLE OUTPUT:
不要停下来啊!
"""
)

Expand Down Expand Up @@ -76,13 +72,9 @@ def summary_prompt(bangumi_info: Optional[BGM] = None) -> str:
+ """
EXAMPLE INPUT:
{
"origin": "It is... How do you know that? I think you mentioned it in your introduction when you transferred in. Anyway, that's not important. My birthday is April 9th. I've already turned sixteen. I've already turned sixteen. Anyway, thanks for checking in, Alya. See you tomorrow."
}
EXAMPLE JSON OUTPUT:
{
"zh": "在这部动漫新番中,主角久世政近的邻座是一个名叫艾莉莎的女孩。艾莉莎通常对政近表现出冷漠的态度,但有时她会用俄语小声地向他撒娇。政近实际上拥有母语级别的俄语听力,能够理解艾莉莎的话,但他选择装作听不懂。艾莉莎误以为政近不懂俄语,所以她才会在他面前展示出她真实的一面。两人之间有着一种甜蜜的氛围,但他们都试图隐藏这一点。在对话中,艾莉莎纠正了政近关于她生日的错误认知,告诉他她的生日是4月9日,并且她已经16岁了。这段对话增加了他们之间的亲密感,让人对他们的关系发展充满期待。"
}
It is... How do you know that? I think you mentioned it in your introduction when you transferred in. Anyway, that's not important. My birthday is April 9th. I've already turned sixteen. I've already turned sixteen. Anyway, thanks for checking in, Alya. See you tomorrow.
EXAMPLE OUTPUT:
在这部动漫新番中,主角久世政近的邻座是一个名叫艾莉莎的女孩。艾莉莎通常对政近表现出冷漠的态度,但有时她会用俄语小声地向他撒娇。政近实际上拥有母语级别的俄语听力,能够理解艾莉莎的话,但他选择装作听不懂。艾莉莎误以为政近不懂俄语,所以她才会在他面前展示出她真实的一面。两人之间有着一种甜蜜的氛围,但他们都试图隐藏这一点。在对话中,艾莉莎纠正了政近关于她生日的错误认知,告诉他她的生日是4月9日,并且她已经16岁了。这段对话增加了他们之间的亲密感,让人对他们的关系发展充满期待。
"""
)

0 comments on commit d4a9078

Please sign in to comment.