??
- ??
- ??? ?? ??? ?? ???? ??? ??????
- ??? ??
- ????
- Python? ??? ?? ? ?? ??
- .NET Core? ?? ??? ?? ??
- Azure? ??
- ?? ??
- ??
-
??
??? ?? ??(LLM)? ??? ??? ???? ???? ???? ???? ?? ??? ??? ?? ????. ??? ?? ???? ?? ???? ??? ??? ? ?? ??? ???? ??? ??? ??? ????. ?? ??? ?? ???? ??? ?? ??? ?? ???? ??? ?? ???? ???? ???? ?? ? ????.
? ????? ???? ???? ?? Python? ???? LLM? ?? ??? ?? ?? ??? .NET Core C# ??????? ?? ? ???? ??? ?????. ?? ??? Microsoft Azure?? ?????.
-
??? ?? ??? ?? ???? ??? ??????
-
??? ???: LLM? ??? ??, ?? ?? ?? ?? ??? ????? ?? ??? ? ????.
-
?? ??: ?? ??? ?? ???, ??, ?? ?? ?? ???? ??? ??? ???? ??? ??? ????.
-
?? ??: ???? ??? ???? ?? ??? ??? LLM? ??? ??? ? ????.
-
??? ??: ?? ??? ???? ???? ?? ??? ?? ????? ???? ???? ??? ????.
-
??? ??
???? ? ??
-
?? ??? ?? Python
- ????? ???? ?????(?: Hugging Face Transformers, PyTorch)
- ?? ??? ?? ?? ? ?? ???? ???
-
??? .NET Core C#
- ?? ?? ??? ?? ??? ??? ?? API ??
- ?? ?? ????? ??? ??? ??? ??
-
Azure ???
-
?? ? ?? ??? ??
- Azure Machine Learning ??? ? ?? ????? ??
- Azure Storage .NET Core ?????? ???? ??
- Azure App Service ?? Azure Function ?? ?? ??? ??
- Azure Key Vault(?? ??)
-
????
????
- Azure ??: Machine Learning Workspace ? App Service? ?? ???? ???? ? ?????.
- Python 3.8 : ?? ?? ??? ?? ??? ?????.
- .NET 6/7/8 SDK: .NET Core C# ??????? ??? ???? ? ?????.
- Visual Studio 2022 ?? Visual Studio Code: ?? IDE.
- Azure CLI: ???? ?? Azure ???? ???? ???? ? ?????.
- Docker(?? ??): ??? ?? ??????? ??????? ? ??? ? ????.
-
Python? ??? ?? ? ?? ??
? ???? ?? ?? ???? LLM ?? ?? ????? ? ??? Hugging Face Transformers? ?????.
5.1 ?? ?? ??
<code>python -m venv venv source venv/bin/activate # 在 Windows 上:venv\Scripts\activate</code>
5.2 ??? ??
<code>pip install torch transformers azureml-sdk</code>
5.3 Azure Machine Learning ?? ?? ???
- ??? ?? ? ?? ??:
<code> az group create --name LLMFinetuneRG --location eastus az ml workspace create --name LLMFinetuneWS --resource-group LLMFinetuneRG</code>
- ????? ??? ?? ??? ?????(config.json ?? ?? ?? ?? ??).
5.4 ?? ?? ????(train.py)
<code>import os import torch from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, Trainer from azureml.core import Workspace, Run # 連接到 Azure ML ws = Workspace.from_config() run = Run.get_context() model_name = "gpt2" # 示例模型 tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name) # 加載自定義數(shù)據集(本地或來自 Azure 存儲) # 示例:Azure ML 中的文本文件或數(shù)據集 train_texts = ["此處輸入您的特定領域文本..."] # 簡化版 train_encodings = tokenizer(train_texts, truncation=True, padding=True) class CustomDataset(torch.utils.data.Dataset): def __init__(self, encodings): self.encodings = encodings def __len__(self): return len(self.encodings["input_ids"]) def __getitem__(self, idx): return {k: torch.tensor(v[idx]) for k, v in self.encodings.items()} train_dataset = CustomDataset(train_encodings) training_args = TrainingArguments( output_dir="./results", num_train_epochs=3, per_device_train_batch_size=2, save_steps=100, logging_steps=100 ) trainer = Trainer( model=model, args=training_args, train_dataset=train_dataset, ) trainer.train() # 保存微調后的模型 trainer.save_model("./fine_tuned_model") tokenizer.save_pretrained("./fine_tuned_model")</code>
5.5 Azure? ?? ??
<code>from azureml.core.model import Model model = Model.register( workspace=ws, model_path="./fine_tuned_model", model_name="myFineTunedLLM" )</code>
? ???? ?? ????? ??? ??? ? ??? ?? ??? ??? Azure Machine Learning? ?????.
-
.NET Core? ?? ??? ?? ??
6.1 .NET Core ? API ???? ??
<code>dotnet new webapi -n FineTunedLLMApi cd FineTunedLLMApi</code>
6.2 ??? ??
-
Azure ?? ?? ?? ?? API ??? ??
- HttpClient
- Newtonsoft.Json(???? JSON.NET? ????? ??) Azure ???? ?? ?? ???? ??
- Azure.Storage.Blobs ?? Azure.Identity
<code>dotnet add package Microsoft.Extensions.Http dotnet add package Microsoft.Azure.Storage.Blob dotnet add package Newtonsoft.Json</code>
6.3 ModelConsumerService.cs
???? ??? ??? ? ???? ????? ?????(?: Azure Container Instance ?? Azure ML? ??? ?? ????? ??). ?? ?? ??? ???? ???? ?? ??? ????.
<code>using Newtonsoft.Json; using System.Net.Http; using System.Text; using System.Threading.Tasks; public class ModelConsumerService { private readonly HttpClient _httpClient; public ModelConsumerService(IHttpClientFactory httpClientFactory) { _httpClient = httpClientFactory.CreateClient("FineTunedModel"); } public async Task<string> GetCompletionAsync(string prompt) { var requestBody = new { prompt = prompt }; var content = new StringContent( JsonConvert.SerializeObject(requestBody), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync("/predict", content); response.EnsureSuccessStatusCode(); return await response.Content.ReadAsStringAsync(); } }</code>
6.4 LLMController.cs
<code>using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; [ApiController] [Route("[controller]")] public class LLMController : ControllerBase { private readonly ModelConsumerService _modelService; public LLMController(ModelConsumerService modelService) { _modelService = modelService; } [HttpPost("complete")] public async Task<IActionResult> CompletePrompt([FromBody] PromptRequest request) { var result = await _modelService.GetCompletionAsync(request.Prompt); return Ok(new { Completion = result }); } } public class PromptRequest { public string Prompt { get; set; } }</code>
6.5 .NET Core ?????? ??
Program.cs ?? Startup.cs:
<code>var builder = WebApplication.CreateBuilder(args); // 注冊 HttpClient builder.Services.AddHttpClient("FineTunedModel", client => { client.BaseAddress = new Uri("https://your-model-endpoint/"); }); // 注冊 ModelConsumerService builder.Services.AddTransient<ModelConsumerService>(); builder.Services.AddControllers(); var app = builder.Build(); app.MapControllers(); app.Run();</code>
-
Azure? ??
-
Azure ? ???:
- ?? .NET Core ??????? ?? ? ??? ?? ?? ?????.
- Azure Portal ?? CLI? ?? ??? ? ?? ????.
<code>python -m venv venv source venv/bin/activate # 在 Windows 上:venv\Scripts\activate</code>
-
Azure ?? (?? ??):
- ??? ?????? ??? ?? ???? ??? ?? ??? ???? ? ?????.
-
Azure Kubernetes Service(AKS) (??):
- ??? ??? ?????.
- Docker? ???? ??????? ??????? ACR(Azure Container Registry)? ?????.
-
?? ??
-
??? ???? ??: ?? ?? ?? ?? ????? ???? ???? ??? ?? ?????.
-
???? ? ??: Azure Application Insights? ???? ??? ?????? ???? ???? ?? ??? ?????.
-
??: Azure Key Vault? ???? ?(API ?, ?? ???)? ?????.
-
?? ?? ??: ??? ?? Azure ML?? ?? ??? ??? ?? ??? ???? ?? ???? ?????.
-
?? ?????: ??? ????? ?? ??? ???? ??? ??? ????.
-
??
Python ? Azure Machine Learning? ???? LLM? ?? ??? ?? ?? .NET Core ??????? ???? ??? ???? AI? ??? ? ????. ???. ? ??? Azure? ???? ???? ?? Python? AI ?????? .NET? ?????? ??? ????? ??? ??? ?????.
??, ??? ????, DevOps? ?? ??? ??? ?? ?? ?? ??? ???? ???? ?? ???? ???? ???? ?? ???? ?? ??????? ??? ???? ?? ??? ??? ? ????.
? ??? .NET Core, Python ? Azure? ???? LLM(?? ?? ??) ?? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

???? Python ?? ?? ?????? ?? ????, "??? ?????, ?? ??"? ???? ??? ??? ??? ?? ??? ?????. 1. ???? ?? ? ??? ?? ?????. ?? ???? ?? ??? ???? ??? ? ? ????. ?? ??, Spoke () ?? ???? ??? ??? ?? ??? ?? ????? ?? ??? ??? ????. 2. ???? ?? ???? ??? ??? ?????? Draw () ???? ???? ????? ?? ???? ?? ??? ???? ??? ???? ?? ?? ?? ??? ????? ?? ?? ????? ?? ?????. 3. Python ?? ???? ???????. ?? ???? ??? ???? ?? ???? ??? ????? ??? ?? ???? ??? ???? ????. ??? ??? ??? ???? ? ??? "?? ??"??????. 4. ???? ? ???? ?? ??? ?????

???? __iter __ () ? __next __ () ???? ???? ?????. ???? ??? ? ??? ????, ?? ???? ?? ??? ??? ???? ?????. 1. ???? ?? () ?? ? ??? ??? ???? ? ?? ??? ?? ? ?? ???? ??? ????. 2. ???? ?? ??? ???? ??? ???? ???? ???? ???? ?? ???? ?????. 3. ???? ???? ?? ??? ?? ? ? ? ??? ?? ? ???????? ? ? ??? ?? ??? ??? ???? ?? ? ? ???? ??????. ?? : ??? ?? ???? ??? ???? ????. ???? ?? ?? ? ??? ?????? ???? ? ?? ?? ? ? ????.

API ??? ??? ??? ?? ??? ???? ???? ???? ????. 1. Apikey? ?? ??? ?? ????, ????? ?? ?? ?? URL ?? ??? ?????. 2. Basicauth? ?? ???? ??? Base64 ??? ??? ??? ??? ????? ?????. 3. OAUTH2? ?? Client_ID ? Client_Secret? ?? ??? ?? ?? ?? ??? BearEtroken? ???????. 4. ?? ??? ???? ?? ?? ?? ???? ????? ???? ?? ?? ? ????. ???, ??? ?? ??? ??? ???? ?? ??? ???? ???? ?? ?????.

????? ??? ? ??? ??? ?? ??? ???? ??? zip () ??? ???? ????.? ??? ?? ??? ???? ?? ??? ?? ????. ?? ??? ???? ?? ?? itertools.zip_longest ()? ???? ?? ?? ? ??? ?? ? ????. enumerate ()? ???? ??? ???? ?? ? ????. 1.zip ()? ???? ????? ?? ??? ??? ??? ?????. 2.zip_longest ()? ???? ?? ??? ?? ? ? ???? ?? ? ????. 3. Enumental (Zip ())? ??? ??? ????? ??? ???? ???? ?? ???? ?? ? ????.

inpython, iteratorsareobjectsthatlowloppingthroughcollections __ () ? __next __ ()

Assert? ????? ???? ???? ?? ? ???? ??? ???? ??? ?? ?? ????. ??? ??? ??? ?? ??? ?????, ?? ?? ?? ??, ?? ?? ?? ?? ?? ?? ??? ????? ?? ?? ??? ?? ???? ??? ? ??? ??? ??? ??? ?? ???????. ?? ??? ???? ?? ?? ???? ?? ????? ??? ? ????.

typehintsinpythonsolvetheproblemombiguityandpotentialbugsindynamicallytypedcodebyallowingdevelopscifyexpectiontypes. theyenhancereadability, enablearylybugdetection ? improvetoomingsupport.typehintsareaddedusingaColon (:) forvariblesAndAramete

Python? ???? ????? ???? API? ???? Fastapi? ?????. ?? ??? ?? ????? ?????? ??? ??? ??? ???? ?? ? ? ????. Fastapi ? Asgi Server Uvicorn? ?? ? ? ????? ??? ??? ? ????. ??? ??, ?? ?? ?? ? ???? ?????? API? ???? ?? ? ? ????. Fastapi? ??? HTTP ??? ???? ?? ?? ? Swaggerui ? Redoc Documentation Systems? ?????. ?? ??? ?? URL ?? ??? ?? ? ??? ??, ?? ?? ??? ???? ???? ?? ?? ??? ??? ? ????. Pydantic ??? ???? ??? ?? ???? ???? ????? ? ??? ? ? ????.
