PLaMo API quickstart
PLaMo is a domestic generative AI foundation model independently developed by Preferred Networks. It is entirely newly developed without using existing Large Language Models and excels in responding in Japanese and translating between Japanese and English. This document explains how to use PLaMo via Web API.
Create API key
In order to use the API functionalities of PLaMo, you need to first obtain an API key. You can access PLaMo by HTTP request using API key
Be sure to create an account to issue API key. Please create one at here. After that, please create an API key on the Profile page. Please keep your API key confidential and do not share it with others.
Set your issued API key as the environment variable as below.
export PLAMO_API_KEY="your_api_key"How to send request
By setting your API key in the environment variable, you can use the PLaMo API. It is accessible via an HTTP client and several libraries that utilize the LLM API.
This document covers accessing the PLaMo API using curl and the Python language with the langchain-openai library, and also the openai library.
Request using curl
Since the PLaMo API provides Web APIs, we can access the API using the development tools, such as curl. The example assumes that the PLAMO_API_KEY has already been configured.
$ curl \
-H "Authorization: Bearer ${PLAMO_API_KEY}" \
-H "Content-Type: application/json" \
"https://api.platform.preferredai.jp/v1/chat/completions" \
-d @- << EOF
{
"messages": [
{
"role": "system",
"content": "You are a travel advisor."
},
{
"role": "user",
"content": "Please tell me a recommended one-day sightseeing route in Kanazawa from morning to evening."
}
],
"model": "plamo-2.2-prime"
}
EOFWhen executing that command, you should see results like the following. Note that the actual text generated will vary from inputs.
{
"id": "chat-random-id-string",
"object": "chat.completion",
"created": 1234567890,
"model": "plamo-2.2-prime",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Sure, I....(Omissions in the documentation)",
"tool_calls": []
},
"logprobs": null,
"finish_reason": "stop",
"stop_reason": null
}
],
"usage": {
"prompt_tokens": 100,
"total_tokens": 350,
"completion_tokens": 250
},
"prompt_logprobs": null
}Request using langchain-openai (Python)
The PLaMo API provides a mostly compatible environment with the langchain-openai library. However, because this library uses a different environment variable, you will need to use the name OPENAI_API_KEY.
export OPENAI_API_KEY=$PLAMO_API_KEYTo install the library, follow these steps.
pip install langchain-openaiOnce the installation is complete, create the following file as plamo_example.py.
import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
base_url=f"{os.environ['API_HOST']}/v1",
model="plamo-2.2-prime",
streaming=True,
# other parameters...,
)
messages=[
{"role": "system", "content": "You are a travel advisor."},
{"role": "user", "content": "Please tell me a recommended one-day sightseeing route in Kanazawa from morning to evening."},
]
for chunk in llm.stream(messages):
print(chunk.content, end="", flush=True)You can access the PLaMo API via Python by running this command.
python plamo_example.pyRequest using openai (Python)
The PLaMo API provides a mostly compatible environment with the openai library. However, because this library uses a different environment variable, you will need to use the name OPENAI_API_KEY.
export OPENAI_API_KEY=$PLAMO_API_KEYTo install the library, follow these steps.
pip install openaiOnce the installation is complete, create the following file as plamo_example.py.
import os
from openai import OpenAI
client = OpenAI(
base_url=f"{os.environ['API_HOST']}/v1",
# other parameters...,
)
completion = client.chat.completions.create(
model="plamo-2.2-prime",
messages=[
{"role": "system", "content": "You are a travel advisor."},
{"role": "user", "content": "Please tell me a recommended one-day sightseeing route in Kanazawa from morning to evening."},
],
stream=True,
)
for chunk in completion:
if chunk.choices and chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="", flush=True)You can access the PLaMo API via Python by running this command.
python plamo_example.pyNext steps
If you want to manage API keys as an organization or limit usage, please create a project from the console. Please refer to the PLaMo API Console Manual for instructions on how to use the console.
Complete documentation of API parameters, including their default values, is provided in the API Reference.
