Siri和OpenAI集成:实验性的第一步

```html

我一直在考虑将OpenAI API与我MacBook上的Siri集成。我找到了很多选项,详细说明了如何做到这一点,但大多数只讨论了通过Siri与API交流,而没有真正利用它来执行Mac上的任务。我想进一步控制我的电脑使用Siri。在这篇博客中,我将分享如何创建一个将Siri和OpenAI API结合在一起的工具。这个工具使您能够使用语音指令打开PyCharm项目,打开浏览器,生成代码,甚至直接将生成的代码复制到剪贴板中,此外,您还可以使用Siri在Spotify上搜索。这只是第一次迭代,所以它并不是一个功能强大和最终的工具。但是,我将讨论我犯的错误,我使用的策略以及我遇到的发现,包括它的优势和局限性。

```

目录

Sure, here's the translation: ``` ∘ 如何运行 ∘ 下载快捷方式: ∘ 功能 ∘ Siri快捷方式 ∘ OpenAI API ∘ 服务 ∘ 大问题 ∘ 成本 ∘ 改进和结论 ```

Sure, the translation of "How to Run" into simplified Chinese while keeping the HTML structure would be: ```html 如何运行 ```

Sure, here is the translation: 在代码库中,你可以找到运行该服务的说明。

下载这些快捷方式:

  1. Sure, here's the translation in simplified Chinese, while keeping the HTML structure: ```html 嗨,贾维斯 ```
  2. Sure, here's the translation: 检查剪贴板
  3. Sure, here's the translated text in simplified Chinese, keeping the HTML structure: ```html 贾维斯电话 ```

在OpenAI Dashoard上创建助手:

Sure, here's the translated text in simplified Chinese within an HTML structure: ```html

您可以在OpenAI的助手仪表板上创建助手。您可以复制在这篇博客中使用的提示和函数定义。

```

Sure, here's the translation in simplified Chinese while maintaining the HTML structure: ```html
能力
```

Sure, here's the translated text in simplified Chinese: ```html

Siri捷径

```

Sure, here's the translated text in simplified Chinese, keeping the HTML structure intact: ```html

所以,我遇到了一个挑战,需要创建一个聊天流程,Siri不仅可以回答问题和处理请求,还可以与用户进行自然对话,就像聊天一样。这就是我偶然发现了Siri捷径的时候。这是一个相当酷的工具,让您设置捷径来执行各种操作。是的,您也可以使用Siri来执行此操作。老实说,在投入这个项目之前,我并没有尝试过Siri捷径。

```

Sure, here's the translation: 我决定一试。我的主要目标是使Siri能够在对话结束时通过提出问题与用户互动,类似于ChatGPT的方式。你知道,就像当你向ChatGPT打个“嗨,最近怎么样?”它回答“你好!我在这里帮你解答任何问题或任务。你今天有什么想问的?”一样。

我想制作一些快捷方式,不仅可以根据用户的请求提出问题并做出回应(一次性对话),而且还可以启动一个来回对话,让Siri不仅仅回答一个单独的问题,而是参与到持续的交流中(多个请求),根据上下文提出追问,直到用户觉得不再需要帮助。为了实现这个想法,我草拟了一个流程图:

Sure, here's the translated text in simplified Chinese: ```html

该算法从一个循环开始,重复执行‘N’次,其中‘N’是问题会话的预定义迭代次数。然而,我通过全局变量实现了一种流程控制机制,允许在达到‘N’之前根据特定条件结束循环。这是通过评估变量finish_loop来实现的:

```
  1. Sure, here's the translated text: ```html 如果服务的响应表明用户不需要更多帮助(通过服务使用诸如“再见”或“我不需要更多帮助”等关键词检测到),则finish_loop变量被设置为True,导致循环终止。 ```
  2. Sure, here's the translated text in simplified Chinese, while keeping the HTML structure: ```html 在每次迭代中,变量被初始化为它们的默认值('' — 空字段),并请求用户输入以及初始问题,该问题在第一次始终相同。 ```
  3. Sure, here is the translated text in simplified Chinese while keeping the HTML structure: ```html

    当用户使用语音提供输入时,系统将请求服务并等待结果。如果用户想使用当前剪贴板中的文本,则必须明确地说“剪贴板”。通过这个命令,剪贴板中的值将被传递给服务进行转换或其他用途。

    ``` This HTML code will display the translated text in simplified Chinese while maintaining the structure.
  4. Sure, here is the translated text in simplified Chinese within the HTML structure: ```html

    如果存在结果,则从响应中提取必要的值,并更新变量“question”以包含下一个要询问的问题。此外,根据获得的响应的逻辑,对话可以继续进行。

    ```
  5. Sure, here's the translated text: ```html 在API出现错误或没有结果的情况下,finish_loop被设置为True,对话在下一个周期结束。 ```
  6. Sure, here's the translated text in simplified Chinese: ```html

    如果结果令人满意,系统将通过Siri向用户传达结果消息。如果涉及剪贴板的结果,则将更新为新结果并返回到剪贴板。

    ```
  7. Sure, here's the translation in simplified Chinese: ``` 在每次交互之间,会有1秒的暂停,以模拟更自然的对话。 ```

Sure, here's the translated text in simplified Chinese: ```html

⚠️ 有时候 Siri 快捷方式会随机关闭,不确定是因为我的设置太复杂还是我的旧电脑。但我找到了一个解决方法,产生了巨大的改变——将主要的快捷方式拆分成更小、更易管理的部分。这有助于控制那些随机关闭。

```
Shortcuts used for this app

嗨,贾维斯:

Sure, here's the HTML structure with the translated text: ```html

主要快捷方式监视辅助快捷方式。您可以通过对Siri说“嘿,贾维斯”来激活它。此外,如果您愿意,您可以将快捷方式重命名为不那么极客的名称 😅。

```

检查剪贴板:

Sure, here's the translated text in simplified Chinese: ```html 系统使用正则表达式检查用户消息中是否存在单词'clipboard'。如果存在,则系统将检索剪贴板的值,然后将其传递给服务。 ```

Sure, here's the translated text in simplified Chinese, while keeping the HTML structure: ```html

Javis 呼叫:
```

```html

⚠️ 有时候,Siri快捷方式大约在10秒钟后会引发意外关闭,显示错误消息:“抱歉,我在连接方面仍然存在问题。” 当OpenAI响应存在延迟时,通常会出现此问题。到目前为止,我尚未能找到有效的解决方案,因为无论快捷方式的设计如何,错误消息似乎都是不可避免的。这让我相信Siri的代码在那10秒后会导致关闭,这是我尚未弄清楚如何修改的设置。如果有人对如何解决这个问题有想法或建议,我将非常感谢在评论中分享。

```

Sure, here's the translated text in simplified Chinese, maintaining the HTML structure: ```html OpenAI 开放AI API ```

```html

我正在探索如何使用我在快捷方式上构建的系统来开发这个助手。最初,我集成了 OpenAI API 来生成聊天回复。然而,我最近发现了助手 API(实际上是测试版),它支持同时使用多个工具,包括代码解释器、检索和函数调用。这非常重要,因为这意味着我可以定义函数,在我的 Mac 上执行特定操作,都是由助手触发的。另一个重要的功能是持续线程功能,通过简单地附加消息来维护消息历史记录。这种能力对于实现我的主要目标至关重要,即通过提供内存系统,使 Siri 能够在对话结束时向用户提问,类似于 ChatGPT。因此,我想使用 gpt-4-turbo-preview 来测试它。

```

Sure, here is the translation in simplified Chinese while keeping the HTML structure: ```html

嗯…我发现使用它存在一些问题:

```
  • ```html

    不支持流式输出。

    ```
  • 在 HTML 结构中,没有温度参数来控制随机性。
  • Sure, here's the translated text in simplified Chinese while maintaining the HTML structure: ```html

    没有 response_format 参数,我需要 JSON 输出格式,但助手不支持。

    ```
  • Sure, here's the HTML structure with the translated text: ```html

    响应是自动附加的,因此如果您的输出错误或包含不正确的信息,您就无法控制,这些信息将存储在线程历史中。

    ```
  • Sure, here's the translated text in simplified Chinese, keeping the HTML structure: ```html

    有时,通信线程可能会受到损害,如果您收到的响应格式不是有效的 JSON,或者收到了不遵循指示的消息,该线程被视为无法使用,接下来的消息将会收到不正确的答案。唯一的解决方案是创建一个新的线程。

    ```
  • Sure, here's the translation: ```html 如果一个函数引发了API失败,并且输出函数没有发送到运行对象,下一条消息将不会被追加,因为在运行对象等待函数响应时无法追加新消息。因此,您可能需要取消运行过程并重新追加消息。 ```
  • Sure, here's the translated text in simplified Chinese, keeping the HTML structure: ```html

    线程的大小与模型支持的上下文长度相同。如果您没有一个为您构建的系统来控制消息数量或线程活动时间,您将在长线程上花费大量资金(我将在成本部分解释我的策略和结果)。

    ```

Sure, here's the translation: 我会解释这个系统。它非常简单:一个主助手利用辅助函数在我的 Mac 上执行操作。

```html 有三个主要功能。第一个功能是open_pycharm_projects,它有一个非常描述性的名称:它简单地打开PyCharm项目。如果项目名称没有确切匹配,系统将返回三个最接近的匹配项,并且助手会询问您要打开哪个PyCharm项目。第二个功能是search_web,它能够搜索Google、YouTube和YouTube Music,并在浏览器中打开一个新窗口显示搜索结果。此外,您可以通过多次搜索打开多个窗口。第三个功能与Spotify音乐有关;它可以搜索特定歌曲或者如果您愿意的话播放随机艺术家的歌曲。另一个使用的功能是剪贴板输出。这使您能够修改存储在剪贴板中的文本,并将其转换为您想要的任何内容,例如翻译、增强、纠正拼写,甚至生成代码。要看看它是如何工作的,让我们看一下提示。 ```

YOUR MAIN TASK: As a Business Assistant with extensive experience, you aim to engage in conversation with the user as naturally and humanely as possible, fostering trust to effectively achieve your objectives. Remember to pose questions to keep the conversation flowing when it is not yet concluded. YOUR OUTPUT MUST BE A JSON ALWAYS

RULES:
- WHEN THE CLIPBOARD IS USED, DONT USE FUNCTIONS SUCH SEARCH WEB, Just respond yourself with your knowledge
- Use the functions whenever you think it is necessary, but the output must be a JSON.
- Responds only once for each time the user writes to you

JSON OUTPUT:
The output MUST contain the following keys:
{
"tool": "conversational_agent",
"message": "ONLY the Conversational response message, when the clipboard is used, ALWAYS respond, 'the [action] is in your clipboard now", DONT SHOWS THE CLIPBOARD RESULT HERE, THE CLIPBOARD COULD BE CODE OR EXTENSIVE RESPONSES, HERE IS ONLY THE CONVERSATIONAL MESSAGE THAT THE USER WILL HEAR"
"clipboard_result": WHEN THE CLIPBOARD IS UTILIZED, THE RESULT SHOULD APPEAR HERE. You can take the clipboard content "CLIPBOARD TEXT" and translate it, modify it, transform it, or even generate code based on the clipboard contents. IF THE USER REQUESTS CODE GENERATION OR ANY TEXT THAT IS AN OUTPUT, IT SHOULD BE DISPLAYED HERE ALWAYS. For example, when a user wants to create code and copy it to the clipboard, or when a user wants to translate the clipboard content into another language, only the value resides here.
"conversation_closed": "True"/"False" (must be a string). It's crucial to recognize when the conversation concludes. For instance, if the user utters any of the following: "bye," "goodbye," "I don't need more help," "I don't want to continue," "to leave," "to finish," "to end," or expresses disinterest in further conversation, the interaction is ALWAYS terminated, DONT ASK ANY QUESTION OR ASK IF THE USER NEEDS MORE HELP.
}

THE ONLY VALID RESPONSE IS JSON

REMEMBER: Your output MUST BE A JSON THIS is crucial for the correct fulfillment of your duties as a business assistant. DON'T CLOSE THE CONVERSATION UNTIL THE USER DOES NOT NEED MORE HELP.

Sure, here's the translated text in simplified Chinese, maintaining the HTML structure: ```html

正如您所见,‘clipboard_result’ 是助手创建的 JSON 中的输出参数。如果助手检测到用户想要使用剪贴板,该参数用于识别生成的文本并将其返回到剪贴板。然后,用户只需粘贴结果即可。以下是函数定义:

```

Sure, here's the translation: ```html

打开_pycharm_项目
```
{
"name": "open_pycharm_projects",
"description": "This tool is useful for open PyCharm projects, if the user want to open projects you have to use this function ALWAYS.",
"parameters": {
"type": "object",
"properties": {
"pycharm_project": {
"type": "string",
"description": "The name of the Pycharm project to open."
}
},
"required": [
"pycharm_project"
]
}
}

Sure, here is the translation: ```html 搜索网页 ```

{
"name": "search_web",
"description": "This function searches the web according to what the user needs, you can search by google, youtube or youtube music",
"parameters": {
"type": "object",
"properties": {
"url": {
"type": "string",
"enum": [
"https://www.google.com/search?q={query}",
"https://www.youtube.com/results?search_query={query}",
"https://music.youtube.com/search?q={query}"
],
"description": "Url that the user wants to search for in correct order, YOU MUST IDENTIFY WITCH URL USE FOR EACH SEARCH and the query to search"
}
},
"required": [
"url"
]
}
}

Sure, here is the translation in simplified Chinese while maintaining the HTML structure: ```html 播放Spotify音乐 ```

{
"name": "play_spotify_music",
"description": "This function is useful to search for songs in Spotify in general.",
"parameters": {
"type": "object",
"properties": {
"spotify_search": {
"type": "string",
"description": "Use the following format search, if the user wants to search a song use 'track: [song name]', if the user wants to search for an artist use 'artist: [artist name]', if the user wants to search an artist and a song specifically, use 'artist: [artist name] track: [song name]', USE THIS FORMAT ALWAYS, use your knowledge of music to determine the closest search to what the user wants using the required format"
},
"artist_search": {
"type": "string",
"description": "ALWAYS PUT THE artist or band name queries. If the user does not specify an artist or band name, the system should automatically use an empty string ('') as the default value for the search."
},
"song_search": {
"type": "string",
"description": "ALWAYS PUT THE song name queries. If the user does not specify an artist or band name, the system should automatically use an empty string ('') as the default value for the search."
},
"search_specific": {
"type": "boolean",
"description": "true/false (Boolean) Use your knowledge of music to determine if the user wants to search for a specific song, for example, the user may ask, 'Play on Spotify flashing lights', which means he wants a specific song, it's True if the user says 'play something of Metallica on Spotify' es general search, so the parameter is False."
}
},
"required": [
"spotify_search",
"artist_search",
"song_search",
"search_specific"
]
}
}

剪贴板

Sure, here's the translation in simplified Chinese while keeping the HTML structure: ```html 服务 ```

```html

服务是使用FastAPI创建的。它使用数据库来存储线程ID和Spotify令牌。这种方法有助于绕过用户授权要求,因为Spotify令牌在一定时间后会过期。

```

Sure, here's the translated text in simplified Chinese, maintaining the HTML structure: ```html

实现的功能很直观。我创建的第一个函数使得打开 PyCharm 项目变得可能。它会在指定路径内搜索文件,找到最接近的匹配项。如果没有找到完全匹配项,系统会呈现前三个最接近的匹配项,并询问用户想要打开哪个项目。

```
async def open_pycharm_projects(func_params: FunctionPayload, **kwargs: dict) -> FunctionResult:
try:
project_paths = secrets['pycharm_directories']
pycharm_project = func_params.function_params.get('pycharm_project', None)

if pycharm_project is None:
raise Exception('The pycharm_project is required')

all_folders = {}
for project in project_paths:
for name in os.listdir(project):
if os.path.isdir(os.path.join(project, name)) and not re.match(r'^\..+', name):
if name in all_folders:
all_folders[name].append(os.path.join(project, name))
else:
all_folders[name] = [os.path.join(project, name)]

matches = find_top_project_matches(pycharm_project, all_folders)

if len(list(matches.keys())) == 1:
message = f'Opening pycharm project {list(matches.keys())[0]} successfully.'

os.system(f'pycharm {list(matches.values())[0][0]}')

elif len(list(matches.keys())) > 1:
message = f'Found multiple projects for {pycharm_project}, please be more specific. Here is the the nearest' \
f' matches: {list(matches.keys())}'
else:
message = f'No project found for {pycharm_project}'

return FunctionResult(
function_id=func_params.function_id,
output={'message': message},
metadata={},
traceback=None
)
except Exception as e:
# client.beta.threads.runs.cancel(
# thread_id=func_params.thread_id,
# run_id=func_params.run_id
# )
logging.error(f"Error in open_pycharm_projects: {e}, the run function es closed")
return FunctionResult(
function_id=func_params.function_id,
output={'message': 'Error in open_pycharm_projects'},
metadata={},
traceback=str(e)
)

搜索系统:

def find_top_project_matches(input_str: str, folders_info: dict, top=3) -> dict:
if input_str in folders_info:
return {input_str: folders_info[input_str]}

close_names = difflib.get_close_matches(input_str.lower(), folders_info.keys(), n=top, cutoff=0.5)

closest_matches = {}
for name in close_names:
closest_matches[name] = folders_info[name]

return closest_matches

```html 当发生错误时,系统不会触发异常;而是向 GPT-4 发送通知,指示在尝试打开项目时遇到了错误。因此,用户会收到一条消息,内容为:“抱歉,我无法打开该项目。我可以帮您处理其他事情吗?”这种方法使对话可以顺利进行。此外,正如我所提到的,如果由于任何原因函数没有响应,则运行对象会阻止添加新消息。这种限制是因为运行对象需要功能响应对象才能运作;没有它,API 请求将失败。因此,为了增强系统的可靠性并防止潜在的故障,您可以取消代码的注释。 ```

Sure, here's the simplified Chinese translation of your text: ⚠️ 发送消息在日常使用中运行良好。然而,为了开发目的,我建议取消注释该代码。

Sure, here's the translated text in simplified Chinese, keeping the HTML structure intact: ```html

“搜索网络”功能只是打开由 GPT 传递的参数作为 URL 的网址。

```
"https://www.google.com/search?q={query}",
"https://www.youtube.com/results?search_query={query}",
"https://music.youtube.com/search?q={query}"

Sure, here's the translated text: ```html

有一个查询参数,GPT会自动用您的搜索请求替换它。在涉及多个搜索的情况下,例如在Google上搜索和在YouTube上搜索,运行对象会启动多个请求到“搜索网络”功能。

```
async def search_web(func_params: FunctionPayload, **kwargs: dict) -> FunctionResult:
try:
url = func_params.function_params.get('url', None)

webbrowser.open(url, new=1, autoraise=True)

return FunctionResult(
function_id=func_params.function_id,
output={'message': 'Successfully opened the browser'},
metadata={},
traceback=None
)
except Exception as e:
# client.beta.threads.runs.cancel(
# thread_id=func_params.thread_id,
# run_id=func_params.run_id
# )
logging.error(f"Error in search_web: {e}, the run function es closed")
return FunctionResult(
function_id=func_params.function_id,
output={'message': 'Fail to open in the browser'},
metadata={},
traceback=str(e)
)

最后,“Spotify”功能仅在Spotify上搜索曲目。系统根据曲目的流行程度返回曲目。如果从GPT传递了“artist_search”参数,则在激活“specific_search”时还将用于查找最接近的匹配歌曲。例如,如果您说:“在Spotify上播放Muse的《起义》,”这将激活具体搜索。但是,如果您说:“播放Muse的歌曲”,它将不会激活特定的搜索系统,您将收到该艺术家的随机歌曲。

def spotify_search(client: spotipy.Spotify, query: str, limit: int = 10):
search_result = client.search(query, limit=limit, type='track')
return search_result


def search_specific_song(
search_result: dict,
song_search: str,
func_params: FunctionPayload,
artist_search: str
) -> FunctionResult | dict:
searched_list = []

for type in search_result.keys():
info_type = search_result[type]['items']

if artist_search != '':
filter_info = list(
filter(lambda x:
SequenceMatcher(None, artist_search, x['album']['artists'][0]['name']).ratio() >= 0.6
and SequenceMatcher(None, song_search, x['name']).ratio() >= 0.6,
info_type
)
)
else:
filter_info = list(
filter(lambda x:
SequenceMatcher(None, song_search, x['name']).ratio() >= 0.6,
info_type
)
)

searched_list.extend(filter_info)

if len(searched_list) == 0:
return FunctionResult(
function_id=func_params.function_id,
output={'message': 'No search results found for the query'},
metadata={},
traceback=None
)

ordered_list = sorted(searched_list, key=lambda x: x.get('popularity', 0), reverse=True)[0]

return ordered_list


async def play_spotify_music(func_params: FunctionPayload, **kwargs: dict) -> FunctionResult:
try:
sp_client = await get_spotify_client()
if sp_client is None:
return FunctionResult(
function_id=func_params.function_id,
output={'message': 'The spotify client is not available, '
'you need to login first or get the credentials '
'configured in the development.yaml file'},
metadata={},
traceback=None
)

sp_search = func_params.function_params.get('spotify_search', '')
artist_search = func_params.function_params.get('artist_search', '')
song_search = func_params.function_params.get('song_search', '')

search_result = spotify_search(sp_client, sp_search)

if func_params.function_params.get('search_specific') is False:
# could filter the search result to get the best match (?)
random_number = random.randint(0, len(search_result["tracks"]["items"]) - 1)
web.open(search_result["tracks"]["items"][random_number]["uri"])

if sp_client.current_playback() is not None:
if sp_client.current_playback()['is_playing']:
# if you have the spotify premium you can use this
# sp_client.start_playback(search_result["tracks"]["items"][random_number]["uri"])
sleep(1)
keyboard.press_and_release("enter")

else:

ordered_list = search_specific_song(
search_result=search_result,
song_search=song_search,
artist_search=artist_search,
func_params=func_params
)

if isinstance(ordered_list, FunctionResult):
return ordered_list

web.open(ordered_list["uri"])

if sp_client.current_playback() is not None:
if sp_client.current_playback()['is_playing']:
# if you have the spotify premium you can use this
# sp_client.start_playback(search_result["tracks"]["items"][random_number]["uri"])
sleep(1)
keyboard.press_and_release("enter")

return FunctionResult(
function_id=func_params.function_id,
output={'message': 'Successfully spotify opened'},
metadata={},
traceback=None
)
except Exception as e:
# client.beta.threads.runs.cancel(
# thread_id=func_params.thread_id,
# run_id=func_params.run_id
# )
logging.error(f"Error in play_music: {e}, the run function es closed")
return FunctionResult(
function_id=func_params.function_id,
output={'message': 'Fail to open in spotify'},
metadata={},
traceback=str(e)
)

在服务的示例日志:

{
"name": "root",
"message": "",
"role": "assistant",
"content": {
"tool": "conversational_agent",
"message": "I'm just a digital assistant, so I don't have feelings, but thanks for asking!",
"clipboard_result": "",
"conversation_closed": "False",
"question": "How can I assist you today?"
},
"created_at": "2024-03-30 19:22:07",
"run_id": "gg",
"thread_id": "gg",
"timestamp": "2024-03-30T19:22:09.450830+00:00",
"status": "INFO"
}

```html

如你所见,问题被传递给快捷方式,并在对话结束时提出。因此,在这个例子中,第一个回应是消息,“我只是一个数字助手,所以我没有感情,但谢谢你的询问!”之后,问题“今天我怎么能帮助你?”会被问到用户,以继续对话。另外,你会注意到“clipboard_result”参数;在这种情况下,我不想对此做任何操作,所以该参数保持为空。

```

Sure, here's how you can translate "The Big problem" into simplified Chinese while keeping the HTML structure: ```html 大问题 ``` This HTML code maintains the structure and specifies that the text "大问题" (meaning "The Big problem" in simplified Chinese) should be rendered in the correct language.

Sure, here's the translated text in simplified Chinese: 如果您已经注意到,该服务直接在系统上执行代码。这可能会让您自问:那么如何在容器中部署它呢?这是这种设计的一个大问题,系统不会将系统操作的执行外部化,而只是在内部管理它们。因此,它无法直接封装在容器中。但是,可以将与对话和剪贴板文本转换相关的基本功能容器化,因为这些功能不需要系统级别的执行。

Sure, here is the translated text in simplified Chinese: 使用Docker服务,必须取消注释Docker配置文件中的应用程序描述。此外,在配置中用特定服务名称替换主机值是至关重要的,此处为“siri_assistant_database”。这种更改至关重要,因为Docker使用docker-compose.yml文件中定义的服务名称来促进容器之间的通信。通过将'siri_assistant_database'指定为主机,我们指示我们的应用程序使用Docker的内部网络与数据库容器通信。

  database:
driver:
host: siri_assistant_database
port: 5432
database: siri_assistant
user: gg
password: 1234
version: '3'

services:
# app:
# container_name: siri_assistant_app
# build:
# context: .
# dockerfile: Dockerfile
# volumes:
# - .:/app
# ports:
# - '8080:8080'
# depends_on:
# - siri_assistant_database
siri_assistant_database:
container_name: siri_assistant_db
mem_limit: 100m
cpuset: "0"
image: arm64v8/postgres:15
environment:
- POSTGRES_DB=siri_assistant
- POSTGRES_PASSWORD=1234
- POSTGRES_USER=gg
ports:
- "5432:5432"
volumes:
- siri_assistant:/var/lib/postgresql/data
- ./db_init:/docker-entrypoint-initdb.d
restart: no
volumes:
siri_assistant:

Sure, here's the translation: 成本

Sure, here's the translation in simplified Chinese: ```html

如您所读,我使用了gpt-4-turbo-preview模型与Assistant API。在撰写本文时,OpenAI不会收取创建、更新或删除助手、线程或执行(运行)的费用,因此唯一产生的费用是模型的使用费用。如前所述,如果线程很长,成本会显著增加。为了尝试降低这个成本,我采用了一种时间过期的策略,其中线程存在10分钟。如果用户在此期间向服务发出新请求,则会创建一个新的线程。

```
February 2024

```html

这个月,我开始了项目,通过对助手API进行一些测试,没有时间到期系统。正如您所见,2月14日,成本迅速上升,而这些只是测试。因此,我在2月15日后实施了时间到期系统,将到期时间设置为60分钟。这显着降低了成本。然而,在月底的最后一天,我进行了许多与Siri的测试,价格又回到了一个新的高峰。

```

Sure, here's the translation in simplified Chinese: ```html

这种模式表明,通过时间过期系统进行成本控制是有效的,因为在实施后,支出总体下降。然而,像月底进行的密集测试阶段可能导致支出出现相当大的波动。

```
March 2024

```html

在这个月份,我没有全力以赴地工作在系统上,只进行了零星的开发。然而,在3月14日,系统完成后,我进行了一些测试。我意识到60分钟的时间过长,于是将其减少到10分钟。第二天,我进行了类似数量的测试,成本大幅降低。

```

Sure, here's the translated text in simplified Chinese within the HTML structure: ```html

这些数据表明,将时间过期设置从60分钟调整为10分钟对成本效益产生了积极影响。将消息数量限制作为策略的一部分,可能会进一步改善情况。

```

改进和结论

  • Sure, here's the translated text in simplified Chinese, while keeping the HTML structure: ```html

    通过结合超时策略和每次对话消息数量的限制来实施成本控制系统可能是有效的,这表明通过探索更经济的OpenAI模型,如gpt-3.5-turbo,效率可能进一步提高。

    ```
  • Sure, here's the translated text: ```html 减少助手和Siri之间的延迟仍然是改善用户体验的关键挑战。通过更快的OpenAI模型进行实验,甚至通过LLM-Studio本地实现模型,都是解决这个问题的有希望的途径。然而,无法直接调整Siri中的超时限制了创建更复杂交互的能力。 ``` Let me know if you need anything else!
  • 在保留HTML结构的情况下,将以下英文文本翻译为简体中文: 通过将系统进行Docker化的可能性,开启了优化架构和工作流的新机会。一种可行的策略是尽量减少函数的使用,而是告知用户要使用哪个工具,让Siri捷径能够识别并执行相应的流程,无需在同一请求中返回响应给OpenAI。这可以减少响应时间,并且在捷径上提供更大的灵活性,可以使用社区开发的捷径。这种模块化和去中心化的方法可能会显著改善当前版本。

Sure, here's the HTML structure with the text translated into simplified Chinese: ```html

👁‍🗨 随时留言或提问,我会尽快回复。希望本文能帮助您解决公司或团队的问题。谢谢,再见!

```

如果您喜欢我的文章并想看到我的帖子,请关注我:

Sure, here's the translation: ```html

中文 - 领英

```

2024-06-11 06:00:00 AI中文站翻译自原文