Skip to content

Commit

Permalink
Merge pull request #136 from crestalnetwork/feat/llm-creative
Browse files Browse the repository at this point in the history
Feat: llm creative
  • Loading branch information
taiyangc authored Jan 31, 2025
2 parents 17e8201 + 879fcd9 commit 0e2fbde
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 66 deletions.
16 changes: 10 additions & 6 deletions app/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,20 @@ def initialize_agent(aid):
model_name=agent.model,
openai_api_key=config.deepseek_api_key,
openai_api_base="https://api.deepseek.com",
presence_penalty=1,
streaming=False,
frequency_penalty=agent.frequency_penalty,
presence_penalty=agent.presence_penalty,
temperature=agent.temperature,
timeout=90,
)
input_token_limit = 60000
else:
llm = ChatOpenAI(
model_name=agent.model,
openai_api_key=config.openai_api_key,
frequency_penalty=agent.frequency_penalty,
presence_penalty=agent.presence_penalty,
temperature=agent.temperature,
timeout=60,
presence_penalty=1,
)

# ==== Store buffered conversation history in memory.
Expand Down Expand Up @@ -266,7 +269,8 @@ def initialize_agent(aid):
if twitter_prompt:
# deepseek only supports system prompt in the beginning
if agent.model.startswith("deepseek"):
prompt_array.insert(0, ("system", twitter_prompt))
# prompt_array.insert(0, ("system", twitter_prompt))
pass
else:
prompt_array.append(("system", twitter_prompt))
if agent.prompt_append:
Expand All @@ -282,8 +286,8 @@ def formatted_prompt(state: AgentState):
# logger.debug(f"[{aid}] formatted prompt: {state}")
return prompt_temp.invoke({"messages": state["messages"]})

# hack for deepseek
if agent.model == "deepseek-reasoner":
# hack for deepseek, it doesn't support tools
if agent.model.startswith("deepseek"):
tools = []

# Create ReAct Agent using the LLM and CDP Agentkit tools.
Expand Down
25 changes: 25 additions & 0 deletions docs/create_agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ AGENT_NAME="IntentKit"
# Notice: Currently, the deepseek-reasoner does not support any skills.
MODEL="gpt-4o-mini"

# Agent temperature (0.0~2.0)
# The randomness of the generated results is such that
# the higher the number, the more creative the results will be.
# However, this also makes them wilder and increases the likelihood of errors.
# For creative tasks, you can adjust it to above 1, but for rigorous tasks,
# such as quantitative trading, it’s advisable to set it lower, around 0.2.
TEMPERATURE=0.7

# Agent frequency penalty (-2.0~2.0)
# The frequency penalty is a measure of how much the AI is allowed to repeat itself.
# A lower value means the AI is more likely to repeat previous responses,
# while a higher value means the AI is more likely to generate new content.
# For creative tasks, you can adjust it to 1 or a bit higher.
FREQUENCY_PENALTY=0.0

# Agent presence penalty (-2.0~2.0)
# The presence penalty is a measure of how much the AI is allowed to deviate from the topic.
# A higher value means the AI is more likely to deviate from the topic,
# while a lower value means the AI is more likely to follow the topic.
# For creative tasks, you can adjust it to 1 or a bit higher.
PRESENCE_PENALTY=0.0

# Agent initial prompt (the role is system, daily user's role is user)
read -r -d '' PROMPT_TEXT << 'END_OF_PROMPT'
You are an autonomous AI agent.
Expand Down Expand Up @@ -98,6 +120,9 @@ JSON_DATA=$(cat << EOF
"id": "$AGENT_ID",
"name": "$AGENT_NAME",
"model": "$MODEL",
"temperature": $TEMPERATURE,
"frequency_penalty": $FREQUENCY_PENALTY,
"presence_penalty": $PRESENCE_PENALTY,
"prompt": "$PROMPT",
"prompt_append": "$PROMPT_APPEND",
"autonomous_enabled": $AUTONOMOUS_ENABLED,
Expand Down
10 changes: 9 additions & 1 deletion models/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ class Agent(SQLModel, table=True):
)
temperature: Optional[float] = Field(
default=0.7,
description="AI model temperature parameter controlling response randomness (0.0-1.0)",
description="AI model temperature parameter controlling response randomness (0.0~1.0)",
)
frequency_penalty: Optional[float] = Field(
default=0.0,
description="Frequency penalty for the AI model, a higher value penalizes new tokens based on their existing frequency in the chat history (-2.0~2.0)",
)
presence_penalty: Optional[float] = Field(
default=0.0,
description="Presence penalty for the AI model, a higher value penalizes new tokens based on whether they appear in the chat history (-2.0~2.0)",
)
# autonomous mode
autonomous_enabled: Optional[bool] = Field(
Expand Down
106 changes: 53 additions & 53 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions skills/enso/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ class EnsoRouteShortcut(EnsoBaseTool):
"""

name: str = "enso_route_shortcut"
description: str = (
"This tool is used specifically for broadcasting a route transaction calldata to the network. It should only be used when the user explicitly requests to broadcast a route transaction with routeId."
)
description: str = "This tool is used specifically for broadcasting a route transaction calldata to the network. It should only be used when the user explicitly requests to broadcast a route transaction with routeId."
args_schema: Type[BaseModel] = EnsoRouteShortcutInput

def _run(
Expand Down
4 changes: 1 addition & 3 deletions skills/enso/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ class EnsoBroadcastWalletApprove(EnsoBaseTool):
"""

name: str = "enso_broadcast_wallet_approve"
description: str = (
"This tool is used specifically for broadcasting a ERC20 token spending approval transaction to the network. It should only be used when the user explicitly requests to broadcast an approval transaction with a specific amount for a certain token."
)
description: str = "This tool is used specifically for broadcasting a ERC20 token spending approval transaction to the network. It should only be used when the user explicitly requests to broadcast an approval transaction with a specific amount for a certain token."
args_schema: Type[BaseModel] = EnsoBroadcastWalletApproveInput
response_format: str = "content_and_artifact"

Expand Down

0 comments on commit 0e2fbde

Please sign in to comment.