Skip to content

Commit

Permalink
Fixing blogposts (#453)
Browse files Browse the repository at this point in the history
* added light and dark themed images

* Added anchors in .md files
  • Loading branch information
diegoarceof authored Nov 21, 2024
1 parent b0c83a1 commit 1b5f1a6
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 46 deletions.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ authors: [diego]
tags: [SQL, LLMs]
---

import ThemedImage from '../../src/components/themedimg.jsx'

Some people look surprised when they learn which programming language is the most used in today’s industry: believe it or not, it's SQL. According to the 2024 edition of IEEE’s programming languages ranking, SQL is the language most sought after by employers, closely followed by Python and Java. This trend, we think, can be attributed to two main factors: the continuous rise of cloud-based system architectures, and a general lack of deep technical knowledge among end users who still need access to data insights.

So how do LLMs come into play? Large language models have demonstrated high coding capabilities, even in the most esoteric and cryptic languages. Considering SQL’s relatively high-level syntax, in this blog post we’ll try to answer the following question: can LLMs write correct, effective, and meaningful SQL queries? Short answer: Yes – with a little help from some cutting-edge prompt engineering techniques.
Expand Down Expand Up @@ -147,8 +149,10 @@ Curious to see the model in action? We've set up a few interactive demos at [hal

**Baseball Database**: This agent answers questions about a baseball database. It contains a total of 26 tables with 553,693 rows; including information about players, teams, awards, and game statistics. Feel free to try it in this [link](https://hal9.com/demos/baseball_agent).

[![Screenshot of conversation with baseball agent](baseball_agent_ss.png)](https://hal9.com/demos/baseball_agent)
<center><a href="https://hal9.com/demos/baseball_agent"><ThemedImage src="baseball-agent"/></a></center>

**Formula 1 Database**: This agent answers questions about a formula 1 database. It contains a total of 13 tables with 88,380 rows; including circuits, races, drivers, constructors, and seasons. It tracks results, standings, qualifying rounds, lap times, and pit stops, providing a full view of the performance and status of drivers and teams across F1 history. You can try it [here](https://hal9.com/demos/formula1_agentd).

[![Screenshot of conversation with formula 1 agent](formula_1_agent_ss.png)](https://hal9.com/demos/formula1_agentd)
<center><a href="https://hal9.com/demos/formula1_agent"><ThemedImage src="formula-1-agent"/></a></center>


102 changes: 58 additions & 44 deletions website/blog/2024-11-19-Hal9_Swarm/Hal9_Swarm.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
---
title: "Using OpenAI Swarm with Hal9: Unlocking New Potential for Enterprise AI"
authors: "Karan Saxena"
tags:
- "AI"
- "Swarm Intelligence"
authors: [karan]
tags: [AI, Swarm Intelligence]
description: "Explore the integration of OpenAI Swarm with Hal9 to
unlock innovative AI capabilities"
---

import ThemedImage from '../../src/components/themedimg.jsx'

## Using OpenAI Swarm with Hal9: Unlocking New Potential for EnterpriseAI

As enterprises seek innovative ways to harness the power of AI,
combining the best tools for flexibility, speed, and collaborative
insights becomes essential. OpenAI Swarm is a promising approach that
leverages multiple instances of AI models working together in a
coordinated manner, effectively mimicking a \"swarm intelligence\"
coordinated manner, effectively mimicking a "swarm intelligence"
system. When paired with Hal9---a platform optimized for customizing and
deploying generative AI---OpenAI Swarm opens new horizons for
enterprise-level solutions.

In this post, we'll dive into what OpenAI Swarm is, why it's a valuable
asset for enterprise use, and how integrating it with Hal9 can transform
your AI-driven applications. We\'ll also walk through some example code
your AI-driven applications. We'll also walk through some example code
and provide visuals generated with this integration.

### What is OpenAI Swarm?
Expand All @@ -46,67 +46,81 @@ single model may not capture the full spectrum of insights required.

```python
import json import hal9 as h9 from dotenv import
load_dotenv from swarm import Swarm, Agent, repl from recommendations
import book_recommendation, comic_recommendation, movie_recommendation
load_dotenv from swarm import Swarm, Agent, repl
from recommendations import book_recommendation, comic_recommendation, movie_recommendation

load_dotenv()

Define transfer functions def transfer_to_receptionist(): return receptionist
#Define transfer functions
def transfer_to_receptionist():
return receptionist

def transfer_to_book_expert(): return book_expert
def transfer_to_book_expert():
return book_expert

def transfer_to_comic_expert(): return comic_expert
def transfer_to_comic_expert():
return comic_expert

def transfer_to_movie_expert(): return movie_expert
def transfer_to_movie_expert():
return movie_expert

#Define expert agents book_expert = Agent( name="Book Expert", instructions="You are a classic books expert. Provide bookrecommendations.
#If the conversation drifts away, return to the receptionist.", functions=[book_recommendation, transfer_to_receptionist], )
# Define expert agents
book_expert = Agent(
name="Book Expert",
instructions="You are a classic books expert. Provide book recommendations. If the conversation drifts away, return to the receptionist.",
functions=[book_recommendation, transfer_to_receptionist])

comic_expert = Agent( name=\"Comic Expert\", instructions=\"You are an
expert in comics. Provide comic recommendations. If the conversation
drifts away, return to the receptionist.\",
functions=\[comic_recommendation, transfer_to_receptionist\], )
comic_expert = Agent(
name="Comic Expert",
instructions="You are an expert in comics. Provide comic recommendations. If the conversation drifts away, return to the receptionist.",
functions=[comic_recommendation, transfer_to_receptionist])

movie_expert = Agent( name=\"Movie Expert\", instructions=\"You are an
expert in movies. Provide movie recommendations. If the conversation
drifts away, return to the receptionist.\",
functions=\[movie_recommendation, transfer_to_receptionist\], )
movie_expert = Agent(
name="Movie Expert",
instructions="You are an expert in movies. Provide movie recommendations. If the conversation drifts away, return to the receptionist.",
functions=[movie_recommendation, transfer_to_receptionist])

receptionist = Agent( name=\"Receptionist\", instructions=\"You are a
receptionist. Direct users to a book, comic, or movie expert based on
their input.\", functions=\[transfer_to_book_expert,
transfer_to_comic_expert, transfer_to_movie_expert\], )
receptionist = Agent(
name="Receptionist",
instructions="You are a receptionist. Direct users to a book, comic, or movie expert based on their input.",
functions=[transfer_to_book_expert, transfer_to_comic_expert, transfer_to_movie_expert])

client = Swarm() messages = h9.load(\'messages\', \[\]) agents =
{\'Receptionist\': receptionist, \'Comic Expert\': comic_expert, \'Movie
Expert\': movie_expert} agent = agents\[h9.load(\'last_agent\',
\'Receptionist\')\]
client = Swarm()
messages = h9.load('messages', [])
agents = {'Receptionist': receptionist,
'Comic Expert': comic_expert,
'Movie Expert': movie_expert}
agent = agents[h9.load('last_agent', 'Receptionist')]

\# Handle user input user_input = input() messages.append({\"role\":
\"user\", \"content\": user_input})
# Handle user input
user_input = input()
messages.append({"role": "user", "content": user_input})

response = client.run(agent=agent, messages=messages)

for message in response.messages: if message\[\"role\"\] ==
\"assistant\": print(f\"{message\[\'sender\'\]}:
{message\[\'content\'\]}\")
for message in response.messages:
if message["role"] == "assistant":
print(f"{message['sender']}: {message['content']}")

messages.extend(response.messages) agent = response.agent
messages.extend(response.messages) agent = response.agent

h9.save(\'messages\', messages, hidden=True) h9.save(\'last_agent\',
agent.name, hidden=True)
h9.save('messages', messages, hidden=True)
h9.save('last_agent', agent.name, hidden=True)
```

## Code Explanation

This code is a recommendation system using a "swarm" of AI agents on the Hal9 platform, each specializing in a category: books, comics, or movies.

#### • Agents: There are four agents: receptionist, book_expert, comic_expert, and movie_expert. The receptionist determines the user’s interest and directs them to the appropriate expert.
#### • Functionality: Each expert agent provides recommendations in its domain, and if the conversation shifts away, it returns control to the receptionist.
#### • Session Management: The code maintains conversation history and the last active agent, enabling smooth, continuous interactions.
#### • Execution: The system takes user input, selects the relevant agent, generates a response, and logs any tool (function) calls made for recommendations.
This setup allows for interactive, specialized recommendations that adapt to user preferences in real-time.
- **Agents:** There are four agents: receptionist, book_expert, comic_expert, and movie_expert. The receptionist determines the user’s interest and directs them to the appropriate expert.

- **Functionality:** Each expert agent provides recommendations in its domain, and if the conversation shifts away, it returns control to the receptionist.

- **Session Management:** The code maintains conversation history and the last active agent, enabling smooth, continuous interactions.

- **Execution:** The system takes user input, selects the relevant agent, generates a response, and logs any tool (function) calls made for recommendations.

This setup allows for interactive, specialized recommendations that adapt to user preferences in real-time.

## Sample Conversation
![movie recommendations](https://github.com/user-attachments/assets/bdb64b5d-b3df-4fc6-815e-9eae4277c29d)
<center><a href="https://hal9.com/demos/swarm"><ThemedImage src="movie-recommendations"/></a></center>
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1b5f1a6

Please sign in to comment.