Azure OpenAI Code InterpreterでのMatplotlib日本語文字化け回避方法について

浅井 郁哉 25 評価のポイント
2025-02-14T10:18:25.25+00:00

Azure OpenAIのCode Interpreterの使用を検討しています。Matplotlibを使用してグラフを表示する際、日本語の文字が文字化けしてしまいます。

  • ライブラリの追加は不可能でした
  • TIFファイルの拡張子は使用できないため、日本語フォントをZIP形式にしてアップロードしましたが、うまく読み込まれませんでした。

Code Interpreter環境のMatplotlibで日本語表示を実現する方法があれば教えてください。既存の日本語対応フォントがあるのか、または他に解決策があるのか知りたいです。

Azure
Azure
Microsoft が管理する世界のデータ センター ネットワークを介してアプリケーションとサービスを構築、配置、および管理するインフラストラクチャおよびクラウド コンピューティング プラットフォーム。
665 件の質問
0 件のコメント コメントはありません
{count} 件の投票

承認済みの回答
  1. JAYA SHANKAR G S 3,960 評価のポイント Microsoft 外部スタッフ モデレーター
    2025-02-17T07:09:26.16+00:00

    こんにちは 浅井 郁哉,

    zipファイルを追加する際には、正しく使用するためのプロンプトを提供する必要があります。

    以下はファイルをアップロードするために使用されたコードで、ここでは日本の従業員データとフォントのzipファイルをアップロードしました。

    enter image description here

    
    DATA_FOLDER = "data/"
    
    def upload_file(client: AzureOpenAI, path: str) -> FileObject:
    
        with Path(path).open("rb") as f:
    
            return client.files.create(file=f, purpose="assistants")
    
    arr = os.listdir(DATA_FOLDER)
    
    assistant_files = []
    
    for file in arr:
    
        filePath = DATA_FOLDER + file
    
        assistant_files.append(upload_file(client, filePath))
    
    file_ids = [file.id for file in assistant_files]
    
    

    次に、以下のようなプロンプトを使用します。

    
    assistant = client.beta.assistants.create(
    
        name="Management Assistant",
    
        instructions="You are an assistant that can help with japanese employee data",
    
        tools=tools_list,
    
        model=api_deployment_name,
    
        tool_resources={"code_interpreter": {"file_ids": file_ids}},
    
    )
    
    thread = client.beta.threads.create()
    
    client.beta.threads.messages.create(thread_id=thread.id, role="user", content="Give me a chart with employee names and salary more than 30000. I have japanese words so if you don't find font for these words, i have given Noto_Sans_JP.zip file, extract it and use NotoSansJP-VariableFont_wght.ttf as font for now and in future conversation")
    
    run = client.beta.threads.runs.create(
    
            thread_id=thread.id,
    
            assistant_id=assistant.id,
    
            instructions="The current date and time is: " + datetime.now().strftime("%x %X") + ". ",
    
        )
    
    completed_run = client.beta.threads.runs.poll(run_id=run.id, thread_id=thread.id)
    
    print(completed_run.status)
    
    messages = client.beta.threads.messages.list(thread_id=thread.id)
    
    format_messages(messages)
    
    

    あなたは必要に応じてプロンプトを使用します。

    出力:

    enter image description here 私は英語からの回答を翻訳していますので、文法に問題があればお許しください。

    0 件のコメント コメントはありません

0 件の追加の回答

並べ替え方法: 最も役に立つ

お客様の回答

回答は、質問作成者が [承諾された回答] としてマークできます。これは、ユーザーが回答が作成者の問題を解決したことを知るのに役立ちます。