Skip to content

Commit

Permalink
add maritalk (#10925)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigo-f-nogueira authored Feb 22, 2024
1 parent 5fb18fc commit 1106a9a
Show file tree
Hide file tree
Showing 10 changed files with 561 additions and 0 deletions.
122 changes: 122 additions & 0 deletions docs/examples/llm/maritalk.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/llm/maritalk.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>\n",
"\n",
"# Maritalk\n",
"\n",
"## Introduction\n",
"\n",
"MariTalk is an assistant developed by the Brazilian company [Maritaca AI](www.maritaca.ai).\n",
"MariTalk is based on language models that have been specially trained to understand Portuguese well.\n",
"\n",
"This notebook demonstrates how to use MariTalk with llama-index through a simple example."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Installation\n",
"If you're opening this Notebook on colab, you will probably need to install LlamaIndex."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install llama-index-llms-maritalk\n",
"!pip install llama-index"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## API Key\n",
"You will need an API key that can be obtained from chat.maritaca.ai (\"Chaves da API\" section)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Usage\n",
"\n",
"### Chat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from llama_index.core.llms import ChatMessage\n",
"from llama_index.llms.maritalk import Maritalk\n",
"\n",
"# To customize your API key, do this\n",
"# otherwise it will lookup MARITALK_API_KEY from your env variable\n",
"# llm = Maritalk(api_key=\"<your_maritalk_api_key>\")\n",
"\n",
"llm = Maritalk()\n",
"\n",
"# Call chat with a list of messages\n",
"messages = [\n",
" ChatMessage(\n",
" role=\"system\",\n",
" content=\"You are an assistant specialized in suggesting pet names. Given the animal, you must suggest 4 names.\",\n",
" ),\n",
" ChatMessage(role=\"user\", content=\"I have a dog.\"),\n",
"]\n",
"\n",
"response = llm.chat(messages)\n",
"print(response)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"### Few-shot examples\n",
"\n",
"We recommend using the `llm.complete()` method when using the model with few-shot examples"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"prompt = \"\"\"Classifique a resenha de filme como \"positiva\" ou \"negativa\".\n",
"\n",
"Resenha: Gostei muito do filme, é o melhor do ano!\n",
"Classe: positiva\n",
"\n",
"Resenha: O filme deixa muito a desejar.\n",
"Classe: negativa\n",
"\n",
"Resenha: Apesar de longo, valeu o ingresso..\n",
"Classe:\"\"\"\n",
"\n",
"response = llm.complete(prompt, stopping_tokens=[\"\\n\"])\n",
"print(response)"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
9 changes: 9 additions & 0 deletions docs/module_guides/models/llms/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ maxdepth: 1
/examples/llm/localai.ipynb
```

## MariTalk

```{toctree}
---
maxdepth: 1
---
/examples/llm/maritalk.ipynb
```

## MistralAI

```{toctree}
Expand Down
153 changes: 153 additions & 0 deletions llama-index-integrations/llms/llama-index-llms-maritalk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
llama_index/_static
.DS_Store
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
bin/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
etc/
include/
lib/
lib64/
parts/
sdist/
share/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
.ruff_cache

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints
notebooks/

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
pyvenv.cfg

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Jetbrains
.idea
modules/
*.swp

# VsCode
.vscode

# pipenv
Pipfile
Pipfile.lock

# pyright
pyrightconfig.json
3 changes: 3 additions & 0 deletions llama-index-integrations/llms/llama-index-llms-maritalk/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
poetry_requirements(
name="poetry",
)
17 changes: 17 additions & 0 deletions llama-index-integrations/llms/llama-index-llms-maritalk/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
GIT_ROOT ?= $(shell git rev-parse --show-toplevel)

help: ## Show all Makefile targets.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}'

format: ## Run code autoformatters (black).
pre-commit install
git ls-files | xargs pre-commit run black --files

lint: ## Run linters: pre-commit (black, ruff, codespell) and mypy
pre-commit install && git ls-files | xargs pre-commit run --show-diff-on-failure --files

test: ## Run tests via pytest.
pytest tests

watch-docs: ## Build and watch documentation.
sphinx-autobuild docs/ docs/_build/html --open-browser --watch $(GIT_ROOT)/llama_index/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# LlamaIndex Llms Integration: Maritalk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_sources()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from llama_index.llms.maritalk.base import Maritalk


__all__ = ["Maritalk"]
Loading

0 comments on commit 1106a9a

Please sign in to comment.