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

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

```

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

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

目录

```

Sure, here's the translated text in simplified Chinese, while keeping the HTML structure intact: ```html ∘ 如何运行 ∘ 下载快捷方式: ∘ 功能 ∘ Siri快捷方式 ∘ OpenAI API ∘ 服务 ∘ 主要问题 ∘ 成本 ∘ 改进与结论 ```

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

如何运行

```

To translate the English text "In the repository, you can find instructions on how to run the service." into simplified Chinese while keeping the HTML structure, you would use the following: ```html 在代码仓库中,您可以找到运行服务的说明。 ``` This HTML code preserves the structure and inserts the translated text in Chinese.

在HTML结构中保持不变,将以下英文文本翻译成简体中文: 下载这些快捷方式:

  1. Sure, here's the text translated into simplified Chinese within an HTML structure: ```html Hey Jarvis

    嘿,贾维斯

    ```
  2. 检查剪贴板
  3. Here's the translation of "Jarvis Call" in simplified Chinese, while maintaining the HTML structure: ```html 贾维斯电话 ```

在OpenAI仪表板上创建助手:

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

您可以在OpenAI的助手仪表板中创建助手。您可以复制在本博客中显示的提示和函数定义。

```

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

Certainly! The translation of "Siri Shortcuts" to simplified Chinese, keeping the HTML structure, would be: ```html Siri 快捷指令 ```

```html

所以,我遇到了这样一个挑战,要创建一个聊天流程,让Siri不仅能够回答问题和处理请求,还能够与用户进行自然的对话,就像在聊天一样。这就是我偶然发现Siri快捷方式的时候。这是一个相当酷的工具,可以让你设置一堆快捷方式来做各种事情。是的,你可以用Siri来使用它。说实话,我在投入这个项目之前从未尝试过Siri快捷方式。

```

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

我决定一试身手。我的主要目标是使Siri能够在对话结束时通过提问与用户互动,类似于ChatGPT的方式。你知道的,就像当你向ChatGPT发送“嗨,有什么新鲜事吗?”时,它会回复“你好!我在这里帮助你解答任何问题或任务。你今天有什么想法?”。

```

Sure, here's the translated text in simplified Chinese, keeping the HTML structure intact: ```html 我想设计一些快捷方式,不仅能够根据用户的请求提出问题并做出回应(一问一答的对话方式)。我的目标是实现一种来回对话的能力,让Siri不仅仅回答一个单一的问题,而是能够进行连续的交流(多次请求),根据上下文提出跟进问题,直到用户觉得不再需要帮助为止。为了实现这个想法,我画了一个流程图: ``` This translation captures the essence of the original text in simplified Chinese, structured for HTML usage.

Sure, here's the translated text in simplified Chinese within the HTML structure: ```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, keeping the HTML structure intact: ```html 在每次迭代中,变量被初始化为它们的默认值(“” — 空字段),并请求用户的输入,同时提供初始问题,第一次始终相同。 ```
  3. Sure, here's the translated text in simplified Chinese: ```html 当用户使用语音输入时,系统将请求服务并等待结果。如果用户想要使用当前剪贴板中的文本,则必须明确地说“剪贴板”。使用此命令,剪贴板中的值将被传递给服务进行转换或其他目的。 ```
  4. Sure, here's the translated text in simplified Chinese: ```html 如果存在结果,则从响应中提取所需的值,并使用下一个要询问的问题更新变量 question。此外,根据所获得响应的逻辑,对话可以继续进行。 ```
  5. 在发生API错误或无结果的情况下,finish_loop被设为True,对话在下一个循环中结束。
  6. Sure, here's the translated text within the HTML structure: ```html 如果结果满意,系统将通过Siri向用户传达结果消息。如果涉及剪贴板的结果,将更新为新结果并返回到剪贴板。 ```
  7. Sure, here's the translated text in simplified Chinese: ```html 在每次交互之间,都会有一秒的暂停,以模拟更自然的对话。 ```

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

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

```
Shortcuts used for this app

嘿,贾维斯:

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

Translated Text

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

``` This HTML structure contains the translated text in simplified Chinese.

检查剪贴板:

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

Sure, the translation of "Jarvis Call:" into simplified Chinese while keeping HTML structure would look like this: ```html Jarvis Call: 贾维斯呼叫: ``` In this example: - "Jarvis Call:" is kept in English for clarity and context. - `贾维斯呼叫:` provides the translation in simplified Chinese within a `` tag, with `lang="zh-CN"` indicating the language code for simplified Chinese.

```html

Translate to Chinese

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

```

Sure, here's the HTML structure with the text "OpenAI API" translated to simplified Chinese: ```html OpenAI API

OpenAI API

```

```html

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

```

Sure, here's the translation: 好吧...我发现了一些使用它时的问题:

  • 在不支持流式输出。
  • 在 HTML 结构中保持不变,将以下英文文本翻译为简体中文: 没有温度参数来控制随机性。
  • Sure, here's the translated text in simplified Chinese, keeping the HTML structure: ```html

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

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

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

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

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

    ```
  • Sure, here's the translated text in simplified Chinese: ```html 如果一个函数引发 API 失败,并且输出函数未发送到运行对象,那么下一条消息将不会被追加,因为在运行对象等待函数的响应时,不能追加新消息。因此,您可能需要取消运行过程并再次追加消息。 ``` Copy and paste this into your HTML structure.
  • Sure, here's the translated text in simplified Chinese, while keeping the HTML structure: ```html

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

    ```

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

我将解释系统。这很简单:一个主要助手利用辅助功能在我的 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 HTML structure with the translated text: ```html

正如您所看到的,“clipboard_result”是助手创建的JSON中的输出参数。如果助手检测到用户想要使用剪贴板,此参数用于标识生成的文本并将其返回到剪贴板。然后,用户可以简单地粘贴结果。以下是函数定义:

```

Sure, here's the translation in simplified Chinese: ```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"
]
}
}

To translate "search_web" into simplified Chinese while keeping the HTML structure intact, you would use the following: ```html 搜索网页 ``` This translates "search_web" to "搜索网页" in simplified Chinese characters.

{
"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's the translation: ```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: ```
剪贴板
```

To translate "Service" into simplified Chinese while keeping the HTML structure, you would write: ```html 服务 ``` Here, `服务` preserves the HTML structure while displaying the translated text "服务" (which means "Service" in simplified Chinese).

```html

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

```

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

实现的功能很简单。我创建的第一个函数可以打开PyCharm项目。它在您指定的路径中搜索文件,以找到最接近的匹配。如果找不到完全匹配项,系统会显示前3个最接近的匹配项,并询问用户想要打开哪个项目。

```
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

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

Translated Text

当发生错误时,系统不会触发异常;相反,它会向 GPT-4 发送通知,指示在尝试打开项目时遇到了错误。因此,用户将收到一条消息,其中包含“抱歉,我无法打开项目。我能帮你做些其他的事情吗?”的提示。这种方法使对话可以顺利进行。此外,正如我所提到的,运行对象在任何原因下没有从函数获得响应时,会阻止新消息的添加。这种限制是因为运行对象需要一个函数响应对象来操作;没有它,API 请求将失败。因此,为了增强系统的可靠性并防止潜在的失败,您可以取消对代码的注释。

``` This HTML structure contains the translated text in simplified Chinese while keeping the original structure intact.

Here is the translated text in simplified Chinese while keeping the HTML structure: ```html

⚠️ 发送消息在日常使用中运行良好。然而,为了开发目的,我建议取消注释该代码。

```

Sure, here is the translation in simplified Chinese while keeping the HTML structure: ```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上进行另一次搜索,Run Object会发起多个请求到“搜索网页”功能。 ```

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的‘Uprising’”,这将激活特定搜索。然而,如果你说,“播放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)
)

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

服务示例日志:

```
{
"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 the translated text in simplified Chinese: ```html
大问题
```

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

Sure, here's the translated text: ```html 要使用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 in simplified Chinese, while keeping the HTML structure: ```html 成本 ```

```html

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

``` This HTML snippet contains the translated text in simplified Chinese while maintaining the structure suitable for display on a webpage.
February 2024

```html

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

```

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

该模式表明,通过时间到期系统进行成本控制是有效的,因为在其实施后,支出普遍减少。尽管如此,像在月底进行的那样的密集测试阶段可能导致支出大幅增加。

```
March 2024

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

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

```

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

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

```

改进和结论

  • Sure, here is the translation of your text into simplified Chinese while keeping the HTML structure: ```html

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

    ``` Let me know if you need any further assistance!
  • Sure, here's the translated text in simplified Chinese, keeping the HTML structure: ```html 减少助手与Siri之间的延迟仍然是改善用户体验的关键挑战。尝试更快的OpenAI模型,甚至通过LLM-Studio在本地实现模型,是解决这个问题的有希望的途径。然而,无法直接调整Siri中的超时限制了创建更复杂交互的能力。 ```
  • 将系统进行Docker化的可能性打开了优化架构和工作流程的新机会。一个可行的策略是尽量减少函数的使用,而是告诉用户使用哪个工具,从而允许Siri快捷方式识别并执行相应的流程,无需在同一请求中将响应返回给OpenAI。这可以减少响应时间,并且在快捷方式方面提供更大的灵活性,可以使用社区开发的快捷方式。这种模块化和去中心化的方法可能是当前版本的显着改进。

```html

留言

请随意留言或提问,我会尽快回复。希望这篇文章能帮助你为你的公司或团队找到解决方案。谢谢,再见!

```

Sure, here's the translated text in simplified Chinese, keeping the HTML structure: ```html 如果您喜欢我的文章并想要查看我的帖子,请关注我: ```

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

Medium- LinkedIn

```

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