讯飞星火接口调用,可以结合fastapi生成个人助手
from sparkai.llm.llm import ChatSparkLLM, ChunkPrintHandlerfrom sparkai.core.messages import ChatMessage
import re
import pandas as pd
#星火认知大模型Spark Max的URL值,其他版本大模型URL值请前往文档(https://www.xfyun.cn/doc/spark/Web.html)查看
SPARKAI_URL = 'wss://spark-api.xf-yun.com/v1.1/chat'
#星火认知大模型调用秘钥信息,请前往讯飞开放平台控制台(https://console.xfyun.cn/services/bm35)查看
SPARKAI_APP_ID = '###################'
SPARKAI_API_SECRET = '###################'
SPARKAI_API_KEY = '###################'
#星火认知大模型Spark Max的domain值,其他版本大模型domain值请前往文档(https://www.xfyun.cn/doc/spark/Web.html)查看
SPARKAI_DOMAIN = 'general'
def search_sparkai(keyword):
spark = ChatSparkLLM(
spark_api_url=SPARKAI_URL,
spark_app_id=SPARKAI_APP_ID,
spark_api_key=SPARKAI_API_KEY,
spark_api_secret=SPARKAI_API_SECRET,
spark_llm_domain=SPARKAI_DOMAIN,
streaming=False,
)
messages = role="user",content=keyword)]
handler = ChunkPrintHandler()
generations = spark.generate(, callbacks=)
data = str(generations)
return data
def get_text(t):
m=t.split("text='")[1]
if len(m) >1:
m=m.split("', message")[0]
else:
return t
return m
# 提取包含特定词汇的句子
def getEglish(data):
pattern = r"\b+(?:+)*\b"
matches = re.findall(pattern, data)
# 过滤掉包含特定词汇的字符串
unwanted_words = ['generations', 'text', 'message', 'content', 'run','n','my']
unwanted_pattern = r'\b(' + '|'.join(unwanted_words) + r')\b'
filtered_matches = for match in matches if not re.search(unwanted_pattern, match)]
seen = set()
unique_filtered_matches = for i, match in enumerate(filtered_matches) if
match not in seen and not seen.add(match)]
if unique_filtered_matches:
return unique_filtered_matches[0]
else:
return None 星火没有阿里的用的顺 感谢分享 感谢 刚好在了解这方面的{:1_927:} 讯飞星火AI专用啊 通义大模型和这个是同种类型的吗 感谢分享多谢 一直都是用阿里的,试试讯飞看,感谢分享 感谢分享
页:
[1]
2