İçeriğe geç
KAMPANYA Kurumsal Web Paketi — $499'dan başlayan fiyatlar Web & Logo Tasarımı · Kurumsal E-posta · LiteSpeed + CloudLinux · Imunify360 Güvenlik · cPanel Yönetim · 3 Gbps DDoS Koruması 00 Gün 00 Saat 00 Dk 00 Sn
AIOR

Developing with the OpenAI API — Overview and Practical Usage

Sektör topluluğu — sorularınız, deneyimleriniz ve duyurularınız için.

Developing with the OpenAI API — Overview and Practical Usage

Aior

Administrator
Staff member
Joined
Apr 2, 2023
Messages
895
Reaction score
2
Points
18
Age
40
Location
Turkey
Website
aior.com
1/3
Thread owner

OpenAI ve Modern Yazılım Geliştirme​

OpenAI'nin sunduğu LLM (Large Language Model) ailesi — özellikle GPT-4 Turbo, GPT-4o ve o1 modelleri — modern uygulama geliştirme manzarasını köklü biçimde değiştirdi. Doğal dil işleme (NLP) görevleri, kod üretimi, content generation, summarization, translation, soru-cevap sistemleri artık birkaç satır API çağrısıyla erişilebilir hizmetler. AIOR olarak müşteri uygulamalarımızda OpenAI'nin sunduğu yetenekleri entegre ediyor, müşteri destek chatbot'ları, içerik üretim pipeline'ları, sınıflandırma sistemleri ve veri özetleme servisleri geliştiriyoruz.

API Erişimi ve Anahtar Yönetimi​

OpenAI API'sini kullanmak için https://platform.openai.com üzerinden hesap açıp API anahtarı oluşturmanız gerekir. Anahtar her zaman güvende tutulmalıdır — kod tabanına commit edilmemeli, ortam değişkenleri veya sırlar yönetim sistemi (AWS Secrets Manager, HashiCorp Vault, Doppler) üzerinden geçirilmelidir.

Code:
export OPENAI_API_KEY="sk-..."

veya .env dosyasında:

Code:
OPENAI_API_KEY=sk-...

Production'da rate limit'leri yönetmek için organization-level kotalar belirleyin; dev ortamı ve prod ortamı için ayrı anahtarlar kullanın.

Python ile İlk API Çağrısı​

Resmi Python SDK'yı kurun:

Code:
pip install openai

Basit bir chat completion isteği:

Code:
from openai import OpenAI
import os

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "Sen yardımcı bir asistansın."},
        {"role": "user", "content": "Python'da dosya nasıl okunur?"}
    ],
    temperature=0.7,
    max_tokens=500,
)

print(response.choices[0].message.content)

model alanı hangi modeli kullanacağınızı belirler. gpt-4o-mini hızlı ve ucuzdur; gpt-4o daha güçlüdür; o1-preview complex reasoning gerektiren görevler için tasarlandı.

Sistem Mesajları ve Prompt Engineering​

Modelin davranışını system mesajıyla şekillendirebilirsiniz. İyi yazılmış sistem mesajları:

Code:
system_msg = '''Sen AIOR müşteri destek asistanısın. Yanıtların:
1. Türkçe ve İngilizce olarak iki dilde yaz
2. Teknik terimleri parantez içinde aç
3. Adım numarası ver
4. Her zaman güvenlik etkisini belirt
5. Hosting konuları dışında soruları AIOR destek ekibine yönlendir'''

Bu yapı modelin tutarlı ve marka diline uygun yanıt vermesini sağlar.

Streaming Yanıtlar​

Uzun yanıtlarda kullanıcı bekleyişini azaltmak için streaming kullanın:

Code:
stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "AI etiği hakkında detaylı yaz"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="", flush=True)

ChatGPT arayüzündeki yazıyı yazma efekti tam olarak budur. Frontend'de Server-Sent Events (SSE) veya WebSocket ile akıtılır.

Function Calling​

Modelin sizin tanımladığınız fonksiyonları çağırması — yani LLM'in agent-like davranması:

Code:
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Belirtilen şehir için güncel hava durumu",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {"type": "string", "description": "Şehir adı"}
            },
            "required": ["city"]
        }
    }
}]

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Bursa'da hava nasıl?"}],
    tools=tools,
)

tool_call = response.choices[0].message.tool_calls[0]
print(tool_call.function.name)  # "get_weather"
print(tool_call.function.arguments)  # {"city": "Bursa"}

Bu altyapı RAG (Retrieval-Augmented Generation), API entegrasyonu, agent sistemleri için temel mekanizmadır.

Maliyet Yönetimi​

OpenAI fiyatlandırması token bazlıdır. Her 1000 input token ve 1000 output token için ayrı ücret. Maliyet yönetimi için:

Model seçimi: basit görevler için gpt-4o-mini, complex reasoning için gpt-4o, sadece gerektiğinde o1
Cache: aynı prompt'a aynı yanıt cache'lenip tekrar API çağrısı yapılmasın
Max tokens: gereksiz uzun yanıtları engellemek için max_tokens sınırla
Embeddings: tekrar tekrar generate yerine bir kez embed et, vector DB'de sakla, similarity search yap

Güvenlik ve Compliance​

OpenAI'ye gönderilen veriler EU GDPR / TR KVKK kapsamında değerlendirilir. Hassas veri içeriyorsa:

- OpenAI'nin Enterprise tier'ı veya Azure OpenAI Service kullanın (data residency garantili)
- Kişisel verileri prompt'a koymadan önce maskeleyin (PII redaction)
- Log retention politikalarını gözden geçirin (API logs OpenAI sunucularında 30 gün tutulur)

AIOR ve LLM Hizmetleri​

AIOR olarak müşteri projelerinde LLM entegrasyonu önemli bir hizmet alanımız. Chatbot, içerik üretim pipeline'ı, döküman özetleme, otomatik etiketleme, RAG tabanlı arama sistemleri kuruyoruz. Hosting altyapımızda LLM uygulamaları için optimize edilmiş Python + Redis + PostgreSQL + pgvector stack hazır geliyor.


OpenAI and Modern Software Development​

OpenAI's family of LLMs (Large Language Models) — particularly GPT-4 Turbo, GPT-4o and the o1 models — has fundamentally reshaped the modern app-development landscape. Natural language processing (NLP) tasks, code generation, content creation, summarisation, translation, Q&A systems are all reachable today via a few lines of API calls. At AIOR we integrate OpenAI capabilities into customer applications — building support chatbots, content production pipelines, classification systems and data summarisation services.

API Access and Key Management​

To use the OpenAI API, sign up at https://platform.openai.com and generate an API key. Keys must always be kept secure — never commit them to a code repository; pass them via environment variables or a secrets manager (AWS Secrets Manager, HashiCorp Vault, Doppler).

Code:
export OPENAI_API_KEY="sk-..."

or in a .env file:

Code:
OPENAI_API_KEY=sk-...

In production, set organisation-level quotas to manage rate limits; use separate keys for dev and prod environments.

First API Call in Python​

Install the official Python SDK:

Code:
pip install openai

A simple chat completion request:

Code:
from openai import OpenAI
import os

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "How do you read a file in Python?"}
    ],
    temperature=0.7,
    max_tokens=500,
)

print(response.choices[0].message.content)

The model field selects which model to use. gpt-4o-mini is fast and cheap; gpt-4o is more powerful; o1-preview is designed for tasks requiring complex reasoning.

System Messages and Prompt Engineering​

Shape the model's behaviour through the system message. A well-crafted system message:

Code:
system_msg = '''You are the AIOR customer support assistant. Your responses must:
1. Be written in both Turkish and English
2. Define technical terms in parentheses
3. Use numbered steps
4. Always note security implications
5. Refer questions outside hosting to the AIOR support team'''

This structure keeps the model's output consistent with your brand's voice.

Streaming Responses​

For long answers, use streaming to reduce user wait time:

Code:
stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write at length about AI ethics"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        print(chunk.choices[0].delta.content, end="", flush=True)

This is exactly what produces the ChatGPT-style typing effect. In a frontend, it's piped via Server-Sent Events (SSE) or WebSocket.

Function Calling​

The model can call functions you define — letting the LLM behave like an agent:

Code:
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Current weather for a given city",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {"type": "string", "description": "City name"}
            },
            "required": ["city"]
        }
    }
}]

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "What's the weather like in Bursa?"}],
    tools=tools,
)

tool_call = response.choices[0].message.tool_calls[0]
print(tool_call.function.name)  # "get_weather"
print(tool_call.function.arguments)  # {"city": "Bursa"}

This is the foundation for RAG (Retrieval-Augmented Generation), API integrations and agent systems.

Cost Management​

OpenAI pricing is token-based — separate charges for input and output tokens per 1000. For cost control:

Model selection: gpt-4o-mini for simple tasks, gpt-4o for complex reasoning, o1 only when needed
Caching: reuse responses for repeated identical prompts
Max tokens: cap max_tokens to prevent runaway-long responses
Embeddings: embed once and store in a vector DB, do similarity search instead of regenerating

Security and Compliance​

Data sent to OpenAI falls under EU GDPR / TR KVKK regulations. For sensitive data:

- Use OpenAI's Enterprise tier or Azure OpenAI Service (guaranteed data residency)
- Mask personal data (PII redaction) before placing it in the prompt
- Review log retention policies (API logs stay on OpenAI servers for 30 days)

AIOR LLM Services​

At AIOR, LLM integration is a major service line. We build chatbots, content production pipelines, document summarisers, automated tagging, RAG-based search. Our hosting infrastructure ships an LLM-optimised Python + Redis + PostgreSQL + pgvector stack ready to go.
 

Forum statistics

Threads
891
Messages
898
Members
27
Latest member
AIORAli

Members online

No members online now.

Featured content

AIOR
AIOR TEKNOLOJİ

Tüm ihtiyaçlarınız için Teklif alın

Hosting · Domain · Sunucu · Tasarım · Yazılım · Mühendislik · Sektörel Çözümler

Teklif al

7/24 Destek · Anında yanıt

Back
Top