12 Ollama JSON API Powershell
Ollama serve komutu ile arkaplan hizmeti başlatıyoruz.
ollama serve
Başka bir pencerede veya tab’ta powershell açalım. Aşağıdaki komut ile ollama’nın çalıştığını kontrol edelim.
Invoke-WebRequest http://localhost:11434/
Ollama çağrılarını yaparken json nesneleri kullanıyoruz. En basit çağrımızda model ve süfle (prompt) değerlerini vermemiz gerekir.
{
"model": "ds15",
"prompt": "What is your name?"
}
Aşağıdaki komut ile yukarıdaki json nesnesi ile bir çağrı yapabiliriz.
Invoke-WebRequest -method POST -Body '{"model":"ds15", "prompt":"What is your name?"}' -uri http://localhost:11434/api/generate
Ama bunun sonucu çok anlamlı olmayacaktır.
: 200
StatusCode StatusDescription : OK
: {123, 34, 109, 111…}
Content : HTTP/1.1 200 OK
RawContent : Fri, 21 Feb 2025 20:03:21 GMT
Date: chunked
Transfer-Encoding: application/x-ndjson
Content-Type
{"model":"ds15","created_at":"2025-02-21T20:03:21.095015583Z","response":"\u003cthink…
Headers : {[Date, System.String[]], [Transfer-Encoding, System.String[]], [Content-Type, System.String[]]}
RawContentLength : 4595
RelationLink : {}
Bizim bu isteğe gelen cevabın içeriğini (Content) almamız gerekiyor. Arkasından bunu json’dan çevirelim. Sonucu akış değil bir defada almak için ayrıca stream false değerinide gönderelim.
(Invoke-WebRequest -method POST -Body '{"model":"ds15", "prompt":"What is your name?", "stream": false}' -uri http://localhost:11434/api/generate ).Content | ConvertFrom-json
Cevabımız aşağıdaki gibi olacaktır. Sizin aldığınız cevap, büyük dil modellerini olasıksal çalışması yüzünden, bundan farklı olabilir.
: ds15
model : 2025-02-21T20:06:55.852687211Z
created_at : <think>
response
</think>
. I'm an AI assistant created by DeepSeek. I'll do my best to help you.
My name is DeepSeek-R1-Lite-Preview: True
done : stop
done_reason : {151644, 3838, 374, 697…}
context : 446094159
total_duration load_duration : 15574183
prompt_eval_count : 8
prompt_eval_duration : 10000000
eval_count : 36
eval_duration : 418000000