Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
artitw committed Jul 9, 2023
1 parent c9de25c commit 642c65f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,15 @@ t2t.Transformer.LANGUAGES
### Assistant
Based on Vicuna 13B, which is based on LLaMA, which is not commercially licensed.
Not ChatGPT level but it works well.
To use a dynamic knowledge base, see [![Q&A Assistant Demo](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1hkNgpSmmUA-mzUibqz25xq-E8KYOLuVx?usp=sharing)
```
instructions = "Generate a JSON object that maps English characters as keys and Greek equivalents as values: {"
res = t2t.Assistant().transform([instructions])
#[
# '{\n"a": "α",\n"b": "β",\n"c": "γ",\n"d": "δ",\n"e": "ε",\n"f": "φ",\n"g": "χ",\n"h": "ι",\n"i": "η",\n"j": "κ",\n"k": "λ",\n"l": "μ",\n"m": "ν",\n"n": "ξ",\n"o": "ο",\n"p": "π",\n"q": "ρ",\n"r": "σ",\n"s": "τ",\n"t": "υ",\n"u": "ύ",\n"v": "φ",\n"w": "χ",\n"x": "ψ",\n"y": "ω",\n"z": "ζ"\n}'
#]
```
- To use a dynamic knowledge base, see [![Q&A Assistant Demo](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1hkNgpSmmUA-mzUibqz25xq-E8KYOLuVx?usp=sharing)
- To use with LangChain, see [![LangChain integration](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1K6Kk80w9vjFZ7PL9dPRgVuOPuaWcY4ae?usp=sharing)

### Tokenization
```
Expand Down
92 changes: 92 additions & 0 deletions demos/Text2Text<>LangChain.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "tlg9YpBgnLhE",
"outputId": "895188c2-bdeb-4f0f-bb94-d928a32d07b3"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 73.4/73.4 kB 3.3 MB/s eta 0:00:00\n"
]
}
],
"source": [
"%%bash\n",
"pip install -qq -U text2text"
]
},
{
"cell_type": "code",
"source": [
"from text2text.langchain.text2text_assistant import Text2TextAssistant\n",
"input_text = \"\"\"\n",
"I have a clove of garlic, some brown rice, a few baby bok choy,\n",
"some olive oil, and a few slices of bacon.\n",
"How can I prepare a meal our of these ingredients?\n",
"\"\"\"\n",
"llm = Text2TextAssistant()\n",
"result = llm(input_text)\n",
"print(result)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "a8aELPRAo4HP",
"outputId": "5296cfe9-2b9e-4929-aaa0-ce5a7d5b2420"
},
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"You could make a delicious garlic fried rice with bok choy and bacon! Here's a recipe to follow:\n",
"\n",
"Ingredients:\n",
"\n",
"* 1/2 cup of cooked brown rice\n",
"* 1 small clove of garlic, minced\n",
"* 1/2 cup of baby bok choy, thinly sliced\n",
"* 4-5 slices of bacon, diced\n",
"* 2 tablespoons of olive oil\n",
"* Salt and pepper, to taste\n",
"\n",
"Instructions:\n",
"\n",
"1. Heat the olive oil in a large skillet over medium heat. Add the minced garlic and sauté for about 30 seconds until fragrant.\n",
"2. Add the diced bacon to the skillet and cook for about 3-4 minutes or until crispy. Remove from the skillet and set aside.\n",
"3. In the same skillet, add the sliced bok choy and cook for about 3-4 minutes or until wilted. Season with salt and pepper to taste.\n",
"4. Add the cooked brown rice to the skillet and stir to combine with the bok choy and bacon. Cook for an additional 2-3 minutes or until heated through.\n",
"5. Serve hot and enjoy your delicious garlic fried rice with bok choy and bacon!\n"
]
}
]
}
]
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="text2text",
version="1.2.6",
version="1.2.7",
author="Artit Wangperawong",
author_email="artitw@gmail.com",
description="Text2Text: Crosslingual NLP/G toolkit",
Expand Down

0 comments on commit 642c65f

Please sign in to comment.