Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 346ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
A

API

Recently created Least recently created Recently updated Least recently updated

timmy / Flask CORS 設定 (flask_cors_example.py)

Last active 6 hours ago API CORS Flask Python Security WebDevelopment

此範例使用 flask_cors 啟用跨來源資源共享 (CORS),允許不同網域的客戶端請求 Flask API,避免瀏覽器的同源政策限制,適用於前後端分離專案。

0 0 0 1
1 from flask import Flask, jsonify
2 from flask_cors import CORS
3
4 app = Flask(__name__)
5 CORS(app) # 啟用 CORS,允許跨域請求
6
7 @app.route('/api/data')
8 def get_data():
9 return jsonify({"message": "Hello, CORS is enabled!"})

timmy / Ollama API 客戶端的應用

Last active 6 hours ago AI API LLM NLP ollama python requests

這是一個 OllamaClient 類,用於與 Ollama LLM API 通信,支持發送文字到指定模型處理、添加提示詞,以及獲取可用模型列表,並內建錯誤處理和超時設定。

0 0 0 2
1 import requests
2
3
4 class OllamaClient:
5 def __init__(self, api_url, api_key=None, timeout=30):
6 """
7 初始化 OllamaClient。
8
9 :param api_url: API 基本端點,例如 'http://192.168.88.82:11434'
10 :param api_key: 如果需要身份驗證,填入 API 金鑰;否則為 None。