chainforge-deepseek-extension.py hinzugefügt
Die Extension für die Nutzung von Chainforge
This commit is contained in:
parent
a008b48224
commit
4bf8c56f38
1 changed files with 104 additions and 0 deletions
104
chainforge-deepseek-extension.py
Normal file
104
chainforge-deepseek-extension.py
Normal file
|
@ -0,0 +1,104 @@
|
|||
from chainforge.providers import provider
|
||||
from openai import OpenAI
|
||||
import json
|
||||
|
||||
# LICENSE IS AT THE END
|
||||
# Since deepseek is OpenAi Compatible ... Hooray
|
||||
|
||||
# Define our settings schema
|
||||
CUSTOM_DEEPSEEK_SETTINGS = {
|
||||
"settings": {
|
||||
"api_key": {
|
||||
"type": "string",
|
||||
"title": "API Key",
|
||||
"description": "Your DeepSeek API key, starts with sk-",
|
||||
"default": ""
|
||||
},
|
||||
"api_url": {
|
||||
"type": "string",
|
||||
"title": "API URL",
|
||||
"description": "The base URL for DeepSeek API calls. Note that the v1 here has NO relationship with the model's version.",
|
||||
"default": "https://api.deepseek.com/v1"
|
||||
},
|
||||
"temperature": {
|
||||
"type": "number",
|
||||
"title": "temperature",
|
||||
"description": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.",
|
||||
"default": 1,
|
||||
"minimum": 0,
|
||||
"maximum": 2,
|
||||
"multipleOf": 0.01
|
||||
},
|
||||
"top_p": {
|
||||
"type": "number",
|
||||
"title": "top_p",
|
||||
"description": "An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass.",
|
||||
"default": 1,
|
||||
"minimum": 0,
|
||||
"maximum": 1,
|
||||
"multipleOf": 0.01
|
||||
}
|
||||
},
|
||||
"ui": {
|
||||
"api_key": {
|
||||
"ui:help": "Enter your DeepSeek API key here",
|
||||
"ui:widget": "password" # This makes the input field masked
|
||||
},
|
||||
"api_url": {
|
||||
"ui:help": "Default is the OpenAI compatible DeepSeek API endpoint"
|
||||
},
|
||||
"temperature": {
|
||||
"ui:help": "Defaults to 1.0. Leave at default if you prefer to set top_p.",
|
||||
"ui:widget": "range"
|
||||
},
|
||||
"top_p": {
|
||||
"ui:help": "Defaults to 1.0. Leave at default if you prefer to set temperature.",
|
||||
"ui:widget": "range"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@provider(
|
||||
name="CostumDeepSeek",
|
||||
emoji="🐼",
|
||||
models=["deepseek-chat", "deepseek-reasoner"],
|
||||
rate_limit=3500, # OpenAI's standard RPM limit - dunno about deep-seek
|
||||
settings_schema=CUSTOM_DEEPSEEK_SETTINGS
|
||||
)
|
||||
def custom_deepseek_completion(
|
||||
prompt: str,
|
||||
model: str = "deepseek-chat",
|
||||
api_key: str = "sk-",
|
||||
api_url: str = "https://api.deepseek.com/v1",
|
||||
temperature: float = 1.0,
|
||||
top_p: float = 1.0,
|
||||
**kwargs
|
||||
) -> str:
|
||||
if not api_key:
|
||||
return "Error: API key is required"
|
||||
|
||||
# Initialize client with custom base URL and API key
|
||||
client = OpenAI(
|
||||
api_key=api_key,
|
||||
base_url=api_url
|
||||
)
|
||||
|
||||
try:
|
||||
response = client.chat.completions.create(
|
||||
model=model,
|
||||
messages=[{"role": "user", "content": prompt}],
|
||||
temperature=temperature,
|
||||
top_p=top_p
|
||||
)
|
||||
return response.choices[0].message.content
|
||||
except Exception as e:
|
||||
return f"Error: {str(e)}"
|
||||
|
||||
# Licensed under the MIT license
|
||||
# Copyright (c) 2025 Sebastian Mondial
|
||||
#
|
||||
# Jedem, der eine Kopie dieser Software und der zugehörigen Dokumentationsdateien (die „Software“) erhält, wird hiermit kostenlos die Erlaubnis erteilt, ohne Einschränkung mit der Software zu handeln, einschließlich und ohne Einschränkung der Rechte zur Nutzung, zum Kopieren, Ändern, Zusammenführen, Veröffentlichen, Verteilen, Unterlizenzieren und/oder Verkaufen von Kopien der Software, und Personen, denen die Software zur Verfügung gestellt wird, dies unter den folgenden Bedingungen zu gestatten:
|
||||
#
|
||||
# Der obige Urheberrechtshinweis und dieser Genehmigungshinweis müssen in allen Kopien oder wesentlichen Teilen der Software enthalten sein.
|
||||
#
|
||||
# DIE SOFTWARE WIRD OHNE MÄNGELGEWÄHR UND OHNE JEGLICHE AUSDRÜCKLICHE ODER STILLSCHWEIGENDE GEWÄHRLEISTUNG, EINSCHLIEẞLICH, ABER NICHT BESCHRÄNKT AUF DIE GEWÄHRLEISTUNG DER MARKTGÄNGIGKEIT, DER EIGNUNG FÜR EINEN BESTIMMTEN ZWECK UND DER NICHTVERLETZUNG VON RECHTEN DRITTER, ZUR VERFÜGUNG GESTELLT. DIE AUTOREN ODER URHEBERRECHTSINHABER SIND IN KEINEM FALL HAFTBAR FÜR ANSPRÜCHE, SCHÄDEN ODER ANDERE VERPFLICHTUNGEN, OB IN EINER VERTRAGS- ODER HAFTUNGSKLAGE, EINER UNERLAUBTEN HANDLUNG ODER ANDERWEITIG, DIE SICH AUS ODER IN VERBINDUNG MIT DER SOFTWARE ODER DER NUTZUNG ODER ANDEREN GESCHÄFTEN MIT DER SOFTWARE ERGEBEN.
|
Loading…
Add table
Reference in a new issue