中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

廣州建筑股份有限公司官網(wǎng)seo課程培訓(xùn)學(xué)校

廣州建筑股份有限公司官網(wǎng),seo課程培訓(xùn)學(xué)校,外包優(yōu)化網(wǎng)站,射陽做網(wǎng)站多少錢本文介紹我的開源項(xiàng)目 TelegramChatBot,這是一個基于 OpenAI GPT API 開發(fā)的 telegram 機(jī)器人,具有多模態(tài)交互能力,求 star!感謝大家!在 telegram jokerController_bot 立即體驗(yàn)!歡迎對 GPT 應(yīng)用開發(fā)或?qū)?t…
  • 本文介紹我的開源項(xiàng)目 TelegramChatBot,這是一個基于 OpenAI GPT API 開發(fā)的 telegram 機(jī)器人,具有多模態(tài)交互能力,求 star!感謝大家!
  • 在 telegram @jokerController_bot 立即體驗(yàn)!
  • 歡迎對 GPT 應(yīng)用開發(fā)或?qū)?telegram 開發(fā)有興趣的朋友和我交流

文章目錄

  • 1. 項(xiàng)目簡介
    • 1.1 特點(diǎn)
    • 1.2 狀態(tài)機(jī)設(shè)計(jì)
    • 1.3 數(shù)據(jù)庫設(shè)計(jì)
  • 2. 各功能最小用例
    • 2.1 文本生成
    • 2.2 圖像生成
    • 2.3 語音輸入 & 輸出

1. 項(xiàng)目簡介

1.1 特點(diǎn)

  • 一個由 OpenAI GPT API 驅(qū)動的 telegram 聊天機(jī)器人
  • 主打催眠玩法,通過在 system 參數(shù)中寫入 “咒語” 來避免聊天時忘記催眠角色設(shè)置,支持咒語的增刪查改。
  • 利用多種強(qiáng)大的 API,該機(jī)器人具有多模態(tài)交互能力,包括圖像顯示、語音輸入輸出等。使用API包括
    1. Text generation: gpt-3.5-turbo & gpt-4
    2. Image generation: stable-diffusion-xl-1024-v1-0
    3. Text-to-voice: tts-1
    4. Voice-to-text: whisper-1
  • 下圖展示機(jī)器人的多模態(tài)交互能力,包括圖像生成、語音輸入輸出以及催眠后生成風(fēng)格化文本
    在這里插入圖片描述

1.2 狀態(tài)機(jī)設(shè)計(jì)

  • 機(jī)器人具有多種功能,但是 telegram bot 交互能力有限,難以像桌面軟件或者 web 網(wǎng)頁那樣同時顯示大量信息或布局多種功能的操作 UI。因此機(jī)器人底層設(shè)計(jì)為有限狀態(tài)機(jī)以簡化前端 UI,這樣也更適合在移動端使用
    在這里插入圖片描述

  • 下面給出機(jī)器人的操作菜單以及部分控制界面
    在這里插入圖片描述

1.3 數(shù)據(jù)庫設(shè)計(jì)

  • 需要存儲的用戶信息包括用戶生成文本和語音的 OpenAI API key、用于生成圖像的 Stability AI API key 以及用戶編輯的咒語文本,使用 MySQL 數(shù)據(jù)庫進(jìn)行數(shù)據(jù)持久化,表設(shè)計(jì)如下
    CREATE TABLE IF NOT EXISTS user_info (id INT NOT NULL AUTO_INCREMENT,user_id VARCHAR(190) NOT NULL,user_key VARCHAR(190) NOT NULL,user_img_key VARCHAR(190) NOT NULL,prompts TEXT,PRIMARY KEY (id),UNIQUE KEY (user_id)
    )
    
    其中 prompts 字段存儲 json 格式的咒語文本

2. 各功能最小用例

  • 本節(jié)展示機(jī)器人使用的四個 API 的最簡單調(diào)用方法,讀者可以利用它們開發(fā)自己的 AI 應(yīng)用

2.1 文本生成

  • 本項(xiàng)目使用 OpenAI GPT3.5 或 GPT4.0 模型生成文本,最小用例如下
    from openai import OpenAI
    client = OpenAI(api_key='XXX')	# 填入你的 apiresponse = client.chat.completions.create(model="gpt-3.5-turbo",messages=[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Who won the world series in 2020?"},{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},{"role": "user", "content": "Where was it played?"}]
    )print(response.choices[0].message.content)
    
  • 注意幾點(diǎn)
    1. 本項(xiàng)目使當(dāng)前(2023.11.29)使用的包版本為 openai 1.3.1,文檔參考這里
    2. messages 參數(shù)需要開發(fā)者自行維護(hù),任何時刻,模型記憶僅涵蓋在 message 信息內(nèi)??梢酝ㄟ^ system 字段設(shè)置模型的行為,例如設(shè)定模型的個性或是提供其行為的具體說明等。本 bot 直接將用戶咒語作為 system 參數(shù),并且在組合 messages 的多輪對話時,總是在用戶的最后一條回復(fù)后加上 “,扮演指定角色回答?!?/code> 的附加內(nèi)容,以保證模型永遠(yuǎn)不會忘記角色設(shè)定
    3. 本 bot 調(diào)用以上方法時,還設(shè)置了 stream 參數(shù)要求模型進(jìn)行流式傳輸器回復(fù)內(nèi)容,這樣就能通過多次編輯 bot 的回復(fù)消息內(nèi)容實(shí)現(xiàn)流式顯示,詳見開源代碼
    4. 如果對回答不滿意,只要不將剛剛的回復(fù)內(nèi)容組合進(jìn) messages 參數(shù)列表中,就可以要求模型進(jìn)行重新回答,由于 GPT 模型是概率生成模型,每次重新回答都會有所不同
    5. GPT 模型有上下文長度限制,如果 messages 參數(shù)列表中內(nèi)容太多超出限制就會報(bào)錯,因此本 bot 提供了上下文長度設(shè)置功能來限制組合進(jìn) messages 列表的對話輪數(shù)
    6. 有時我們希望可以語言模型可以按照一定格式進(jìn)行回復(fù),比如我們希望模型在對話過程中自主識別出用戶是否有生成圖像的意圖,如果有就按照用戶當(dāng)前回復(fù)來制圖,這樣就需要模型在每次回復(fù)時不僅回復(fù)自然語言回答,還要回復(fù)一個 “是否生成圖像” 的 bool 變量,這時可以通過設(shè)置 response_format={ "type": "json_object" } 參數(shù)要求模型以 json 格式進(jìn)行返回。本 bot 沒有使用該功能,詳見文檔說明

2.2 圖像生成

  • 本項(xiàng)目使用 stability.ai 的 stable-diffusion-xl-1024-v1-0 模型生成圖像,最小用例如下

    import os
    import io
    import warnings
    from PIL import Image
    from stability_sdk import client
    import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation# Our Host URL should not be prepended with "https" nor should it have a trailing slash.
    os.environ['STABILITY_HOST'] = 'grpc.stability.ai:443'# Sign up for an account at the following link to get an API Key.
    # https://platform.stability.ai/# Click on the following link once you have created an account to be taken to your API Key.
    # https://platform.stability.ai/account/keys# Paste your API Key below.# Set up our connection to the API.
    stability_api = client.StabilityInference(key='XXX', # 填入你的 apiverbose=True, # Print debug messages.engine="stable-diffusion-xl-1024-v1-0", # Set the engine to use for generation.# Check out the following link for a list of available engines: https://platform.stability.ai/docs/features/api-parameters#engine
    )# Set up our initial generation parameters.
    answers = stability_api.generate(prompt="expansive landscape rolling greens with gargantuan yggdrasil, intricate world-spanning roots towering under a blue alien sky, masterful, ghibli",seed=4253978046, # If a seed is provided, the resulting generated image will be deterministic.# What this means is that as long as all generation parameters remain the same, you can always recall the same image simply by generating it again.# Note: This isn't quite the case for Clip Guided generations, which we'll tackle in a future example notebook.steps=50, # Amount of inference steps performed on image generation. Defaults to 30. cfg_scale=8.0, # Influences how strongly your generation is guided to match your prompt.# Setting this value higher increases the strength in which it tries to match your prompt.# Defaults to 7.0 if not specified.width=1024, # Generation width, defaults to 512 if not included.height=1024, # Generation height, defaults to 512 if not included.samples=1, # Number of images to generate, defaults to 1 if not included.sampler=generation.SAMPLER_K_DPMPP_2M # Choose which sampler we want to denoise our generation with.# Defaults to k_dpmpp_2m if not specified. Clip Guidance only supports ancestral samplers.# (Available Samplers: ddim, plms, k_euler, k_euler_ancestral, k_heun, k_dpm_2, k_dpm_2_ancestral, k_dpmpp_2s_ancestral, k_lms, k_dpmpp_2m, k_dpmpp_sde)
    )# Set up our warning to print to the console if the adult content classifier is tripped.
    # If adult content classifier is not tripped, save generated images.
    for resp in answers:for artifact in resp.artifacts:if artifact.finish_reason == generation.FILTER:warnings.warn("Your request activated the API's safety filters and could not be processed.""Please modify the prompt and try again.")if artifact.type == generation.ARTIFACT_IMAGE:img = Image.open(io.BytesIO(artifact.binary))img.save(str(artifact.seed)+ ".png") # Save our generated images with their seed number as the filename.
    
  • 注意幾點(diǎn)

    1. 本項(xiàng)目當(dāng)前(2023.11.29)使用的包版本為 stability-sdk 0.4.0,文檔參考這里
    2. 這個模型是一個 text-to-image 的模型,生成圖像質(zhì)量會顯著受到 prompt 質(zhì)量影響,因此不適合直接用自然語言作為 prompt 來生成圖像。本 bot 利用 GPT 模型的 in-context learning 能力,先把自然語言翻譯成較高質(zhì)量的 image prompt,再調(diào)用該模型生成圖像,這一步輸入給 GPT 模型的 prompt 如下
      IMGPROMPT = "A prompt example for 一個童話般的寧靜小鎮(zhèn),鳥瞰視角,動漫風(fēng)格 is “a painting of a fairy tale town, serene landscape, a bird's eye view, anime style, Highly detailed, Vivid Colors.” "
      IMGPROMPT += "Another prompt example for 雙馬尾動漫少女,藍(lán)黑色頭發(fā),顏色鮮艷 is “a painting of 1girl, blue | black hair, low twintails, anime style, with bright colors, Highly detailed.” "
      IMGPROMPT += "Another prompt example for 擬人化的兔子肖像,油畫,史詩電影風(fēng)格 is “a oil portrait of the bunny, Octane rendering, anthropomorphic creature, reddit moderator, epic, cinematic, elegant, highly detailed, featured on artstation.” "
      IMGPROMPT += "Another prompt example for 黃昏下,大雨中,兩個持刀的海盜在海盜船上決斗 is “Two knife-wielding pirates dueling on a pirate ship, dusk, heavy rain, unreal engine, 8k, high-definition, by Alphonse Mucha and Wayne Barlowe.” "
      IMGPROMPT += "Now write a prompts for "
      
      當(dāng)然,bot 也提供了直接使用用戶輸入內(nèi)容作為 prompt 生成圖像的命令,熟悉 AI 圖像生成方法的用戶可以直接提供高質(zhì)量的 image prompt 序列

2.3 語音輸入 & 輸出

  • 本項(xiàng)目使用 OpenAI tts-1 模型實(shí)現(xiàn)文字轉(zhuǎn)語音,使用 whisper-1 模型實(shí)現(xiàn)語音轉(zhuǎn)文字,最小用例如下
    from pathlib import Path
    from openai import OpenAI
    client = OpenAI(api_key='XXX')	# 填入你的 api# text2voice
    speech_file_path = Path(__file__).parent / "speech.ogg"
    response = client.audio.speech.create(model="tts-1",voice="alloy",input="Hello, World! 你好世界!",response_format='opus'
    )
    response.stream_to_file(speech_file_path)# voice2text
    file_path = Path(__file__).parent / "speech.ogg"
    audio_file = open(file_path, "rb")
    transcript = client.audio.transcriptions.create(model="whisper-1", file=audio_file, response_format="text"
    )
    print(transcript)
    
  • 本項(xiàng)目使當(dāng)前(2023.11.29)使用的包版本為 openai 1.3.1,文檔參考
    • Text-to-voice: tts-1
    • Voice-to-text: whisper-1
http://www.risenshineclean.com/news/22364.html

相關(guān)文章:

  • 湛江有沒有做網(wǎng)站的關(guān)鍵詞seo培訓(xùn)
  • 純css網(wǎng)站騰訊體育nba
  • 電子商務(wù)網(wǎng)站建設(shè)招標(biāo)書網(wǎng)絡(luò)營銷常見的工具
  • 學(xué)做網(wǎng)站初入門教程太原seo代理商
  • 中交路橋建設(shè)網(wǎng)站百度seo工作室
  • 裝飾畫嘉興seo外包公司費(fèi)用
  • 吉林網(wǎng)站備案英文seo實(shí)戰(zhàn)派
  • 修改網(wǎng)站圖標(biāo)seo有名氣的優(yōu)化公司
  • 河南省建設(shè)教育協(xié)會網(wǎng)站口碑營銷的方法
  • 長安網(wǎng)站建設(shè)費(fèi)用查詢網(wǎng)站流量
  • 重慶梁平網(wǎng)站建設(shè)哪家便宜優(yōu)化網(wǎng)站標(biāo)題是什么意思
  • 做qq游戲的視頻秀網(wǎng)站楓樹seo
  • 網(wǎng)站登錄注冊頁面模板下載百度搜索引擎收錄
  • 小型網(wǎng)站開發(fā)用什么語言營銷案例網(wǎng)站
  • 企業(yè)門戶網(wǎng)站建設(shè)渠道服裝市場調(diào)研報(bào)告范文
  • 鄭州網(wǎng)站建設(shè)公司價(jià)格經(jīng)濟(jì)新聞最新消息財(cái)經(jīng)
  • 邢臺做網(wǎng)站口碑好怎么弄推廣廣告
  • 百度收錄網(wǎng)站要多網(wǎng)站策劃書模板
  • 東莞企業(yè)黃頁百度關(guān)鍵詞優(yōu)化送網(wǎng)站
  • 編程線下培訓(xùn)機(jī)構(gòu)廣安seo外包
  • 泗洪網(wǎng)站建設(shè)蘭蔻搜索引擎營銷案例
  • 做網(wǎng)站要做哪些站長工具高清無嗎
  • 網(wǎng)站優(yōu)化標(biāo)題怎么做自媒體平臺注冊入口官網(wǎng)
  • 怎么做動態(tài)網(wǎng)站系統(tǒng)哪里有永久免費(fèi)建站
  • 做網(wǎng)站用什么主機(jī)操作系統(tǒng)品牌網(wǎng)絡(luò)營銷案例
  • web前端概述網(wǎng)站seo專員招聘
  • 2023年東莞疫情最新消息seo關(guān)鍵詞首頁排名代發(fā)
  • asp網(wǎng)站做視頻教程提高網(wǎng)站收錄的方法
  • 一起做陶瓷的網(wǎng)站網(wǎng)絡(luò)推廣引流是做什么的
  • 網(wǎng)站建設(shè)工作室 杭州營銷推廣與策劃