Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cohere's NLP model added and utilised it's methods to create bots in testbase. #117

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
edcb46d
cohere lib added in project dependency
praveensinghrajput23 Sep 3, 2023
68a7e1b
cohere class added and generate and chat method created.
praveensinghrajput23 Sep 3, 2023
544eb7a
cohere bot for response generation of given prompt added in examples
praveensinghrajput23 Sep 3, 2023
a407b39
Revert "cohere bot for response generation of given prompt added in e…
praveensinghrajput23 Sep 3, 2023
7b79192
cohere bot example added for response generation for given prompt
praveensinghrajput23 Sep 3, 2023
3c0294c
cohere chat bot created
praveensinghrajput23 Sep 3, 2023
d14fccf
file renamed
praveensinghrajput23 Sep 3, 2023
d4ed88b
summarize method added to cohere class which is used to get summary o…
praveensinghrajput23 Sep 3, 2023
c82ae2e
summarize bot added in example with a prompt text for which we want t…
praveensinghrajput23 Sep 3, 2023
69a0063
chat history fixes done in chat method of cohere
praveensinghrajput23 Sep 3, 2023
7d03397
docstring added for cohere summarize method for better understanding …
praveensinghrajput23 Sep 3, 2023
f43b5b0
docstring added for better understanding the chat method of cohere class
praveensinghrajput23 Sep 3, 2023
a52072d
doc string added in cohere class for generate method to easy to inter…
praveensinghrajput23 Sep 3, 2023
80da897
cohere chat bot document added
praveensinghrajput23 Sep 3, 2023
81619f5
cohere chat bot doc fixes
praveensinghrajput23 Sep 3, 2023
635e95d
cohere prompt bot document added
praveensinghrajput23 Sep 3, 2023
08fd7b9
cohere summary bot added in textbase docs
praveensinghrajput23 Sep 3, 2023
741c873
side bar positions updated
praveensinghrajput23 Sep 3, 2023
2c05226
Merge branch 'main' of github.com:praveensinghrajput23/textbase into …
praveensinghrajput23 Sep 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs/docs/examples/cohere-chat-bot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
sidebar_position: 1
---

# Cohere Chat bot

This chat bot makes an API call to Cohere and processes the user input and also maintain the chat history of user and system. It uses command model by default. More information added in Cohere Class itself.

```py
from textbase import bot, Message
from textbase.models import Cohere
from typing import List

# Load your Cohere API key
Cohere.api_key = ""

# Prompt for `command` (cohere's model)
MESSAGE = "Is messi better than ronaldo or ronaldo better than messi?"

@bot()
def on_message(message_history: List[Message], state: dict = None):

# Generate `command` (cohere's model) response
bot_response = Cohere.chat(
system_prompt=MESSAGE,
user_name="user",
message_history=message_history, # Assuming history is the list of user messages
model="command",
)

response = {
"data": {
"messages": [
{
"data_type": "STRING",
"value": bot_response
}
],
"state": state
},
"errors": [
{
"message": ""
}
]
}

return {
"status_code": 200,
"response": response
}
```
53 changes: 53 additions & 0 deletions docs/docs/examples/cohere-prompt-bot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
sidebar_position: 2
---

# Cohere Prompt bot

This Prompt bot makes an API call to Cohere and processes the user input and resopond accordingly. It uses command model by default. More information added in Cohere Class itself.

```py
from textbase import bot, Message
from textbase.models import Cohere
from typing import List

# Load your Cohere API key
Cohere.api_key = ""

# Prompt for `command` (cohere's model)
# you add your sample prompts here
SYSTEM_PROMPT = """How much developer can love python language?
"""

@bot()
def on_message(message_history: List[Message], state: dict = None):

# Generate `command` (cohere's model) response
bot_response = Cohere.generate(
system_prompt=SYSTEM_PROMPT,
message_history=message_history, # Assuming history is the list of user messages
model="command",
)

response = {
"data": {
"messages": [
{
"data_type": "STRING",
"value": bot_response
}
],
"state": state
},
"errors": [
{
"message": ""
}
]
}

return {
"status_code": 200,
"response": response
}
```
73 changes: 73 additions & 0 deletions docs/docs/examples/cohere-summarize-bot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
sidebar_position: 3
---

# Cohere Summary bot

This bot makes an API call to Cohere and processes the long user input and retruns short and crisp summary of the given para in different forms. It uses command model by default. More information added in Cohere Class itself.

```py
from textbase import bot, Message
from textbase.models import Cohere
from typing import List

# Load your Cohere API key
Cohere.api_key = ""

# Prompt for `command` (cohere's model)
# you add your sample prompts here
SYSTEM_PROMPT = """"Ice cream is a sweetened frozen food typically eaten as a snack or dessert.
It may be made from milk or cream and is flavoured with a sweetener,
either sugar or an alternative, and a spice, such as cocoa or vanilla,
or with fruit such as strawberries or peaches.
It can also be made by whisking a flavored cream base and liquid nitrogen together.
Food coloring is sometimes added, in addition to stabilizers.
The mixture is cooled below the freezing point of water and stirred to incorporate air spaces
and to prevent detectable ice crystals from forming. The result is a smooth,
semi-solid foam that is solid at very low temperatures (below 2 °C or 35 °F).
It becomes more malleable as its temperature increases.
The meaning of the name ice cream varies from one country to another.
In some countries, such as the United States, ice cream applies only to a specific variety,
and most governments regulate the commercial use of the various terms according to the
relative quantities of the main ingredients, notably the amount of cream.
Products that do not meet the criteria to be called ice cream are sometimes labelled
frozen dairy dessert instead. In other countries, such as Italy and Argentina,
one word is used for all variants. Analogues made from dairy alternatives,
such as goat's or sheep's milk, or milk substitutes
(e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are
lactose intolerant, allergic to dairy protein or vegan.
"""

@bot()
def on_message(message_history: List[Message], state: dict = None):

# Generate `command` (cohere's model) response
bot_response = Cohere.summarize(
text_input=SYSTEM_PROMPT,
message_history=message_history, # Assuming history is the list of user messages
model="command",
length="long"
)

response = {
"data": {
"messages": [
{
"data_type": "STRING",
"value": bot_response
}
],
"state": state
},
"errors": [
{
"message": ""
}
]
}

return {
"status_code": 200,
"response": response
}
```
2 changes: 1 addition & 1 deletion docs/docs/examples/huggingface-bot.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 3
sidebar_position: 4
---

# HuggingFace bot
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/examples/mimicking-bot.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 1
sidebar_position: 5
---

# Mimicking bot
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/examples/openai-bot.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 2
sidebar_position: 6
---

# Open AI bot
Expand Down
42 changes: 42 additions & 0 deletions examples/cohere-chat-bot/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from textbase import bot, Message
from textbase.models import Cohere
from typing import List

# Load your Cohere API key
Cohere.api_key = ""

# Prompt for `command` (cohere's model)
MESSAGE = "Hey there, How are you!"

@bot()
def on_message(message_history: List[Message], state: dict = None):

# Generate `command` (cohere's model) response
bot_response = Cohere.chat(
system_prompt=MESSAGE,
user_name="user",
message_history=message_history, # Assuming history is the list of user messages
model="command",
)

response = {
"data": {
"messages": [
{
"data_type": "STRING",
"value": bot_response
}
],
"state": state
},
"errors": [
{
"message": ""
}
]
}

return {
"status_code": 200,
"response": response
}
43 changes: 43 additions & 0 deletions examples/cohere-prompt-bot/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from textbase import bot, Message
from textbase.models import Cohere
from typing import List

# Load your Cohere API key
Cohere.api_key = ""

# Prompt for `command` (cohere's model)
# you add your sample prompts here
SYSTEM_PROMPT = """how python interpreter works!
"""

@bot()
def on_message(message_history: List[Message], state: dict = None):

# Generate `command` (cohere's model) response
bot_response = Cohere.generate(
system_prompt=SYSTEM_PROMPT,
message_history=message_history, # Assuming history is the list of user messages
model="command",
)

response = {
"data": {
"messages": [
{
"data_type": "STRING",
"value": bot_response
}
],
"state": state
},
"errors": [
{
"message": ""
}
]
}

return {
"status_code": 200,
"response": response
}
62 changes: 62 additions & 0 deletions examples/cohere-summarize-bot/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from textbase import bot, Message
from textbase.models import Cohere
from typing import List

# Load your Cohere API key
Cohere.api_key = ""

# Prompt for `command` (cohere's model)
# you add your sample prompts here
SYSTEM_PROMPT = """"Ice cream is a sweetened frozen food typically eaten as a snack or dessert.
It may be made from milk or cream and is flavoured with a sweetener,
either sugar or an alternative, and a spice, such as cocoa or vanilla,
or with fruit such as strawberries or peaches.
It can also be made by whisking a flavored cream base and liquid nitrogen together.
Food coloring is sometimes added, in addition to stabilizers.
The mixture is cooled below the freezing point of water and stirred to incorporate air spaces
and to prevent detectable ice crystals from forming. The result is a smooth,
semi-solid foam that is solid at very low temperatures (below 2 °C or 35 °F).
It becomes more malleable as its temperature increases.
The meaning of the name ice cream varies from one country to another.
In some countries, such as the United States, ice cream applies only to a specific variety,
and most governments regulate the commercial use of the various terms according to the
relative quantities of the main ingredients, notably the amount of cream.
Products that do not meet the criteria to be called ice cream are sometimes labelled
frozen dairy dessert instead. In other countries, such as Italy and Argentina,
one word is used for all variants. Analogues made from dairy alternatives,
such as goat's or sheep's milk, or milk substitutes
(e.g., soy, cashew, coconut, almond milk or tofu), are available for those who are
lactose intolerant, allergic to dairy protein or vegan.
"""

@bot()
def on_message(message_history: List[Message], state: dict = None):

# Generate `command` (cohere's model) response
bot_response = Cohere.summarize(
text_input=SYSTEM_PROMPT,
message_history=message_history, # Assuming history is the list of user messages
model="command",
)

response = {
"data": {
"messages": [
{
"data_type": "STRING",
"value": bot_response
}
],
"state": state
},
"errors": [
{
"message": ""
}
]
}

return {
"status_code": 200,
"response": response
}
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ tabulate = "^0.9.0"
functions-framework = "^3.4.0"
yaspin = "^3.0.0"
pydantic = "^2.3.0"
cohere = "^4.21"
google-generativeai = "^0.1.0"
rich = "^13.5.2"

Expand Down
Loading