0
0

こちらのAPIを試してみます。

注意
執筆時点では、AWS東京リージョンでは利用できません。

Databricks Foundation Model APIとは?

Databrickモデルサービングでは、専用サービングエンドポイントから最先端のオープンソースモデルへアクセス、クエリーできるFoundation Model APIをサポートするようになりました。Foundation Model APIによって、開発者はご自身の手でモデルデプロイメントを維持管理することなしに、高品質な生成AIモデルを活用したアプリケーションをクイックかつ容易に構築できるようになります。

Foundation Model APIを利用できるワークスペースでは、Foundation Model APIのエンドポイントを確認できます。
Screenshot 2023-12-05 at 15.14.29.png

Databricks Foundation Model APIの活用

ライブラリをインストールします。

%pip install databricks-genai-inference
dbutils.library.restartPython()

llama-2-70b-chatを呼び出します。

from databricks_genai_inference import ChatCompletion

response = ChatCompletion.create(model="llama-2-70b-chat",
                                 messages=[{"role": "system", "content": "You are a helpful assistant."},
                                           {"role": "user","content": "Knock knock."}],
                                 max_tokens=128)
print(f"response.message:{response.message}")

動きました!

response.message:
Who's there? I'm here to help with any questions or tasks you may have.
from databricks_genai_inference import ChatSession

chat = ChatSession(model="llama-2-70b-chat", system_message="You are a helpful assistant.", max_tokens=128)
chat.reply("Knock, knock!")
chat.last # return "Hello! Who's there?"
chat.reply("Guess who!")
chat.last # return "Okay, I'll play along! Is it a person, a place, or a thing?"

chat.history

なんてお手軽な。

[{'role': 'system', 'content': 'You are a helpful assistant.'},
 {'role': 'user', 'content': 'Knock, knock!'},
 {'role': 'assistant', 'content': "\nWho's there?"},
 {'role': 'user', 'content': 'Guess who!'},
 {'role': 'assistant',
  'content': "Okay, I'll play along! Is it a person, a place, or a thing?"}]

エンべディングモデルを呼び出します。

from databricks_genai_inference import Embedding

response = Embedding.create(
    model="bge-large-en",
    input="3D ActionSLAM: wearable person tracking in multi-floor environments")
print(f'embeddings: {response.embeddings}')

エンべディングを取得できます。

embeddings: [[0.050384521484375, 0.0523681640625, -0.019805908203125, -0.0118560791015625, 0.00033473968505859375, 0.01215362548828125, -0.01873779296875, 0.051788330078125, 0.047943115234375, 0.016265869140625, -0.03143310546875, 0.053802490234375, -0.01314544677734375, -0.027374267578125, 0.0021533966064453125, 0.043914794921875, -0.002056121826171875, -0.00612640380859375, 0.0245361328125, -0.00933074951171875, 0.0211944580078125, 0.045074462890625, -0.08319091796875, -0.054443359375, 0.00498199462890625, 0.0257415771484375, 0.03857421875, -0.0284576416015625, 0.043731689453125, 0.06231689453125, 0.02996826171875, -0.021697998046875, 0.032257080078125, -0.058837890625, -0.0283355712890625, -0.0260162353515625,

mpt-7b-instructを呼び出します。

from databricks_genai_inference import Completion

response = Completion.create(
    model="mpt-7b-instruct",
    prompt="Write 3 reasons why you should train an AI model on domain specific data sets.",
    max_tokens=128)
print(f"response.text:{response.text:}")
response.text:['AI models are known to learn better when given task and domain specific training data. The following are a few reasons why it would be beneficial for an organization to prepare their own training data sets and train an AI model on it. 1. Internal requirements of the organization can be best understood by an internally curated data set. 2. Creating and maintaining a privacy protected data set is only possible if the organization is in control of it. 3. Data curation and verification processes can be best executed by the organization themselves.']

一応、日本語でも動作します。

from databricks_genai_inference import Completion

response = Completion.create(
    model="mpt-7b-instruct",
    prompt="ドメイン固有のデータセットでAIモデルをトレーニングすべき3つの理由を挙げてください。",
    max_tokens=128)
print(f"response.text:{response.text:}")
response.text:['3つの理由には、分析データ、マルチバインデース、丁寧な請求書に対する支出セキュリティがあります。\nあいで、データの整合性を保つことができるかもしれないパターンを发見するために、モデルをトレーニングさせています。']
from databricks_genai_inference import ChatCompletion

response = ChatCompletion.create(model="llama-2-70b-chat",
                                 messages=[{"role": "system", "content": "あなたは有能なアシスタントです。日本語で回答します。"},
                                           {"role": "user","content": "日本で一番高い山は"}],
                                 max_tokens=128)
print(f"response.message:{response.message}")
response.message:日本で一番高い山は、富士山です。標高3,776メートルです。

Databricksクイックスタートガイド

Databricksクイックスタートガイド

Databricks無料トライアル

Databricks無料トライアル

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0