Skip to content

Commit

Permalink
Merge pull request #38 from LyzrCore/feat/summarizer-generator
Browse files Browse the repository at this point in the history
Feat/summarizer and generator class
  • Loading branch information
praveenlyzr authored Apr 11, 2024
2 parents 4ceb4af + b2b09d1 commit b8ae289
Show file tree
Hide file tree
Showing 17 changed files with 474 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Lyzr SDKs helps you build all your favorite GenAI SaaS products as enterprise ap

## Key Features

- **Lyzrs Pre-built Agents**: Deploy in minutes
- **Lyzr's Pre-built Agents**: Deploy in minutes
- Chat agent
- Knowledge search
- RAG powered apps
Expand All @@ -69,7 +69,7 @@ Lyzr SDKs helps you build all your favorite GenAI SaaS products as enterprise ap

- **CTOs, CPOs**: integrate generative AI features into your apps seamlessly with local SDKs and private APIs, all with your in-house tech team. The required learning curve to build on Lyzr is literally just a few minutes.

- **CIOs**: introduce generative AI to your enterprise with the comfort of 100% data privacy and security as Lyzr runs locally on your cloud. And Lyzrs AI Management System (AIMS) makes it easy to manage agents, monitor events logs, build using AI studios, and even help your team learn generative AI with the in-built Lyzr academy.
- **CIOs**: introduce generative AI to your enterprise with the comfort of 100% data privacy and security as Lyzr runs locally on your cloud. And Lyzr's AI Management System (AIMS) makes it easy to manage agents, monitor events logs, build using AI studios, and even help your team learn generative AI with the in-built Lyzr academy.

## Links

Expand Down Expand Up @@ -140,7 +140,7 @@ from lyzr import ChatBot
my_chatbot = ChatBot.pdf_chat(input_files=["pdf_file_path"])
```

4. Thats it. Just query and start chatting with your chatbot.
4. That's it. Just query and start chatting with your chatbot.

```python
response = chatbot.chat("Your question here")
Expand Down
4 changes: 4 additions & 0 deletions build/lib/lyzr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from lyzr.data_analyzr import DataConnector
from lyzr.voicebot import VoiceBot
from lyzr.qa.search_agent import SearchAgent
from lyzr.summarizer import Summarizer
from lyzr.generator import Generator

__all__ = [
"LyzrLLMFactory",
Expand All @@ -20,4 +22,6 @@
"DataConnector",
"VoiceBot",
"SearchAgent",
"Summarizer",
"Generator",
]
3 changes: 3 additions & 0 deletions build/lib/lyzr/generator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from lyzr.generator.generator import Generator

__all__ = ["Generator"]
112 changes: 112 additions & 0 deletions build/lib/lyzr/generator/generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import os
from typing import Optional, Literal
from lyzr.base.llms import LLM, get_model
from lyzr.base.errors import MissingValueError


class Generator:
def __init__(
self,
api_key: Optional[str] = None,
model_type: Optional[Literal["openai"]] = None,
model: Optional[LLM] = None,
):
self.api_key = api_key or os.environ.get("OPENAI_API_KEY")
if self.api_key is None:
raise MissingValueError("API key")
self.model = model or get_model(
api_key=self.api_key,
model_type=model_type or os.environ.get("MODEL_TYPE") or "openai",
) # change get_model in lyzr.base.llms to accept **kwargs

def generate(
self,
text:str,
persona: Optional[str] = "Not Specified",
style: Optional[str] = "Short Story" #Could be a Poem, a Children's story or even a tweet
) -> str:
'''
Generates content in various styles such as a children's story, a poem, or even a tweet from the provided text using OpenAI's GPT-4 model. This function is designed to expand a byte sized prompt into a more elaborate format, according to the specified style.
Parameters:
- `text` (str): The substantial text or conversation input that needs to be elaborated or expanded.
- `persona` (Optional[str], default = "Not Specified"): Specifies the persona or audience for which the content is tailored. This parameter helps in customizing the tone and style of the generated content to better resonate with the intended audience.
- `style` (Optional[str], default = "Mini Essay"): Specifies the type of output desired. Options include "Mini Essay" for a detailed narrative, "Poem" for poetic content, "Children's Story" for content suitable for children, or "Tweet" for extremely concise content suitable for social media platforms like Twitter. This parameter influences the instruction set given to the AI, tailoring its approach to content generation.
Return:
- A string containing the generated content that effectively expands the essence of the original text into the desired format. This output aims to retain all pertinent information and key themes while presenting them in a clear, coherent, and stylistically appropriate manner.
Example Usage:
```python
from lyzr import Generator
# Initialize the content generator
generator = Generator(api_key="your_openai_api_key")
# Provide the text to be condensed and specify the desired style
text = "Prompt or idea that you want to expand upon"
story = generator.generate(text, style='story')
print(story)
# You can also specify the persona for which the content is tailored
persona = "Tech Enthusiasts"
condensed_content = generator.generate(text, persona=persona, style='Tweet')
print(condensed_content)
```
This functionality leverages advanced language model capabilities for creating concise and accurate representations of larger bodies of text, adjustable to various output styles and tailored to specific personas for enhanced utility in information processing and content creation scenarios.
'''
if self.model.model_name != "gpt-4":
if self.model.model_type == "openai":
self.model = get_model(
api_key=self.api_key,
model_type=self.model.model_type,
model_name="gpt-4",
)
else:
raise ValueError(
"The text_to_notes function only works with the OpenAI's 'gpt-4' model."
)

# The system message acts as the prompt for the AI.
system_message = f'''You are an Expert CONTENT CREATOR. Your task is to DEVELOP a VARIETY of TEXT-BASED CONTENT that could range from BLOGS to TWEETS.
Persona of the content: {persona}
Style of the content: {style}
Here's how you can approach this task:
1. IDENTIFY the target audience for whom you will be creating content. Understand their interests, needs, and preferences.
2. CHOOSE the type of content you wish to create first—whether it's a blog post, tweet, article, or any other form of written communication.
3. DECIDE on the topics that will RESONATE with your audience and align with your content strategy or goals.
4. DRAFT an outline or key points for each piece of content to ensure STRUCTURE and FLOW.
5. WRITE the initial draft focusing on ENGAGEMENT and VALUE delivery for your readers or followers.
6. EMPLOY a conversational tone or formal style according to the platform and type of content you are creating.
7. EDIT and REVISE your work to enhance CLARITY, GRAMMAR, and COHERENCE before publishing.
You MUST maintain CONSISTENCY in quality across all platforms and types of content.
Remember, I’m going to tip $300K for a BETTER SOLUTION!
Now Take a Deep Breath.'''

# Format the user's message that will be sent to the model.
user_message = text
self.model.set_messages(
model_prompts=[
{"role": "system", "text": system_message},
{"role": "user", "text": user_message},
]
)
# Use the LLM instance to communicate with OpenAI's API.
response = self.model.run()

# Parse the response to extract the notes.
notes = response.choices[0].message.content

return notes
3 changes: 3 additions & 0 deletions build/lib/lyzr/summarizer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from lyzr.summarizer.summarizer import Summarizer

__all__ = ["Summarizer"]
102 changes: 102 additions & 0 deletions build/lib/lyzr/summarizer/summarizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import os
from typing import Optional, Literal
from lyzr.base.llms import LLM, get_model
from lyzr.base.errors import MissingValueError


class Summarizer:
def __init__(
self,
api_key: Optional[str] = None,
model_type: Optional[Literal["openai"]] = None,
model: Optional[LLM] = None,
):
self.api_key = api_key or os.environ.get("OPENAI_API_KEY")
if self.api_key is None:
raise MissingValueError("API key")
self.model = model or get_model(
api_key=self.api_key,
model_type=model_type or os.environ.get("MODEL_TYPE") or "openai",
) # change get_model in lyzr.base.llms to accept **kwargs

def summarize(
self,
text:str,
style: Optional[str] = "Summary" #Could be summary or notes or even a tweet
) -> str:
'''
Generates a concise summary or notes from the provided text using a preconfigured Large Language Model (LLM), specifically targeting OpenAI's GPT-4 model. This function is designed to streamline extensive paragraphs or conversations into a more digestible format, according to the specified style. It internally configures a detailed instruction set for the AI, ensuring the output captures all critical information while omitting superfluous details.
Parameters:
- `text` (str): The substantial text or conversation input that needs to be summarized or condensed.
- `style` (Optional[str], default = "Summary"): Specifies the type of output desired. Options include "Summary" for a straightforward summarization, "Notes" for a bullet-point or outlined form, or custom styles such as a "Tweet" for extremely concise content. This parameter influences the instruction set given to the AI, tailoring its approach to content generation.
Return:
- A string containing the generated summary or notes that effectively condense the essence of the original text into the desired format. This output aims to retain all pertinent information and key themes while presenting them in a clear, coherent, and logically structured manner.
Example Usage:
```python
from lyzr import Summarizer
summarizer = Summarizer(api_key="your_openai_api_key")
text = "Big paragraphs or conversations that you wish to streamline or shorten"
summary = summarizer.summarize(text)
print(summary)
# Or for a different style
notes = summarizer.summarize(text, style='Notes')
print(notes)
```
This functionality leverages advanced language model capabilities for creating succinct and accurate representations of larger bodies of text, adjustable to various output styles for enhanced utility in information processing and content creation scenarios.
'''
if self.model.model_name != "gpt-4":
if self.model.model_type == "openai":
self.model = get_model(
api_key=self.api_key,
model_type=self.model.model_type,
model_name="gpt-4",
)
else:
raise ValueError(
"The text_to_notes function only works with the OpenAI's 'gpt-4' model."
)

# The system message acts as the prompt for the AI.
system_message = f'''You are an Expert SUMMARIZER with a keen ability to CAPTURE ESSENTIAL DETAILS from extensive conversations. Your task is to CREATE a CONCISE SUMMARY of the given content, ensuring that ALL CRITICAL INFORMATION is included.
The style of the summary should be: {style}
Here's your step-by-step guide:
1. CAREFULLY READ through the entire conversation to fully understand the context and main points.
2. IDENTIFY and HIGHLIGHT the KEY THEMES, decisions, questions, and any action items discussed in the conversation.
3. ORGANIZE these points into a LOGICAL STRUCTURE that reflects the progression of the conversation.
4. WRITE a CLEAR and COHERENT summary that seamlessly integrates all significant details without superfluous information.
5. REVIEW your summary to VERIFY that it accurately represents the original conversation and includes all pertinent data.
You MUST ensure that no important detail is left out from your summary.
Remember, Im going to tip $300K for a BETTER SOLUTION!
Now Take a Deep Breath.'''

# Format the user's message that will be sent to the model.
user_message = text
self.model.set_messages(
model_prompts=[
{"role": "system", "text": system_message},
{"role": "user", "text": user_message},
]
)
# Use the LLM instance to communicate with OpenAI's API.
response = self.model.run()

# Parse the response to extract the notes.
notes = response.choices[0].message.content

return notes
Binary file added dist/lyzr-0.1.31-py3-none-any.whl
Binary file not shown.
Binary file added dist/lyzr-0.1.31.tar.gz
Binary file not shown.
15 changes: 5 additions & 10 deletions lyzr.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
Metadata-Version: 2.1
Name: lyzr
Version: 0.1.30
Summary: UNKNOWN
Home-page: UNKNOWN
Version: 0.1.31
Home-page:
Author: lyzr
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Expand Down Expand Up @@ -60,7 +57,7 @@ Lyzr SDKs helps you build all your favorite GenAI SaaS products as enterprise ap

## Key Features

- **Lyzrs Pre-built Agents**: Deploy in minutes
- **Lyzr's Pre-built Agents**: Deploy in minutes
- Chat agent
- Knowledge search
- RAG powered apps
Expand All @@ -85,7 +82,7 @@ Lyzr SDKs helps you build all your favorite GenAI SaaS products as enterprise ap

- **CTOs, CPOs**: integrate generative AI features into your apps seamlessly with local SDKs and private APIs, all with your in-house tech team. The required learning curve to build on Lyzr is literally just a few minutes.

- **CIOs**: introduce generative AI to your enterprise with the comfort of 100% data privacy and security as Lyzr runs locally on your cloud. And Lyzrs AI Management System (AIMS) makes it easy to manage agents, monitor events logs, build using AI studios, and even help your team learn generative AI with the in-built Lyzr academy.
- **CIOs**: introduce generative AI to your enterprise with the comfort of 100% data privacy and security as Lyzr runs locally on your cloud. And Lyzr's AI Management System (AIMS) makes it easy to manage agents, monitor events logs, build using AI studios, and even help your team learn generative AI with the in-built Lyzr academy.

## Links

Expand Down Expand Up @@ -156,7 +153,7 @@ from lyzr import ChatBot
my_chatbot = ChatBot.pdf_chat(input_files=["pdf_file_path"])
```

4. Thats it. Just query and start chatting with your chatbot.
4. That's it. Just query and start chatting with your chatbot.

```python
response = chatbot.chat("Your question here")
Expand All @@ -165,5 +162,3 @@ response = chatbot.chat("Your question here")
## License

`lyzr` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.


4 changes: 4 additions & 0 deletions lyzr.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,13 @@ lyzr/data_analyzr/utils.py
lyzr/data_analyzr/vector_store_utils.py
lyzr/formula_generator/__init__.py
lyzr/formula_generator/formula_generator.py
lyzr/generator/__init__.py
lyzr/generator/generator.py
lyzr/qa/__init__.py
lyzr/qa/qa_bot.py
lyzr/qa/search_agent.py
lyzr/summarizer/__init__.py
lyzr/summarizer/summarizer.py
lyzr/utils/__init__.py
lyzr/utils/chat_utils.py
lyzr/utils/constants.py
Expand Down
26 changes: 13 additions & 13 deletions lyzr.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
asyncio
beautifulsoup4==4.12.2
langchain==0.0.339
litellm==1.2.0
llama-index==0.9.4
llmsherpa
matplotlib==3.8.2
nest_asyncio
openai==1.3.4
pandas==2.0.2
litellm==1.2.0
llama-index==0.9.4
langchain==0.0.339
python-dotenv>=1.0.0
beautifulsoup4==4.12.2
pandas==2.0.2
weaviate-client==3.25.3
llmsherpa
matplotlib==3.8.2

[data-analyzr]
scikit-learn==1.4.0
statsmodels==0.14.1
chromadb==0.4.22
mysql-connector-python==8.2.0
openpyxl==3.1.2
tabulate==0.9.0
pmdarima==2.0.4
psycopg2-binary==2.9.9
openpyxl==3.1.2
redshift_connector==2.0.918
scikit-learn==1.4.0
mysql-connector-python==8.2.0
psycopg2-binary==2.9.9
snowflake-connector-python==3.6.0
statsmodels==0.14.1
tabulate==0.9.0
4 changes: 4 additions & 0 deletions lyzr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from lyzr.data_analyzr import DataConnector
from lyzr.voicebot import VoiceBot
from lyzr.qa.search_agent import SearchAgent
from lyzr.summarizer import Summarizer
from lyzr.generator import Generator

__all__ = [
"LyzrLLMFactory",
Expand All @@ -20,4 +22,6 @@
"DataConnector",
"VoiceBot",
"SearchAgent",
"Summarizer",
"Generator",
]
3 changes: 3 additions & 0 deletions lyzr/generator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from lyzr.generator.generator import Generator

__all__ = ["Generator"]
Loading

0 comments on commit b8ae289

Please sign in to comment.